Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid and spinner on Eclipse IDE
    primarykey
    data
    text
    <p>I do know that this question was discussed many times. I did what I could, sources are installed. To the point: I am using Google sdk - 10, and I am trying to implement spinner with this example: <a href="http://developer.android.com/resources/tutorials/views/hello-spinner.html" rel="nofollow">http://developer.android.com/resources/tutorials/views/hello-spinner.html</a> and still have problem with it. Here is the debug message: </p> <pre><code>AlertController$RecycleListView(ViewGroup).getChildAt(int) line: 3065 /** * Returns the view at the specified position in the group. * * @param index the position at which to get the view from * @return the view at the specified position or null if the position * does not exist within the group */ public View getChildAt(int index) { try { return mChildren[index]; } catch (IndexOutOfBoundsException ex) { return null; } } </code></pre> <p>And here stops execution:</p> <pre><code>return mChildren[index]; </code></pre> <p>What I am doing wrong?</p> <p>Here comes main class:</p> <pre><code>package com.hellospinner.test; import android.app.Activity; import android.os.Bundle; import android.widget.ArrayAdapter; import android.widget.Spinner; public class HelloSpinnerActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Spinner spinner = (Spinner) findViewById(R.id.spinner); ArrayAdapter&lt;CharSequence&gt; adapter = ArrayAdapter.createFromResource(this, R.array.planets_array, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); spinner.setOnItemSelectedListener(new MyOnItemSelectedListener()); } } </code></pre> <p>Here comes my OnItemSelectedListener class:</p> <pre><code>package com.hellospinner.test; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemSelectedListener; import android.widget.Toast; public class MyOnItemSelectedListener implements OnItemSelectedListener { public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int pos, long id) { Toast.makeText(parent.getContext(), "The planet is " + parent.getItemAtPosition(pos).toString(), Toast.LENGTH_LONG).show(); } public void onNothingSelected(AdapterView parent) { } } </code></pre> <p>Here comes main.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" &gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="10dip" android:text="@string/planet_prompt" /&gt; &lt;Spinner android:id="@+id/spinner" android:layout_width="fill_parent" android:layout_height="wrap_content" android:prompt="@string/planet_prompt" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>Here comes strings.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;resources&gt; &lt;string name="app_name"&gt;HelloSpinner&lt;/string&gt; &lt;string name="planet_prompt"&gt;Choose a planet&lt;/string&gt; &lt;string-array name="planets_array"&gt; &lt;item&gt;Mercury&lt;/item&gt; &lt;item&gt;Venus&lt;/item&gt; &lt;item&gt;Earth&lt;/item&gt; &lt;item&gt;Mars&lt;/item&gt; &lt;item&gt;Jupiter&lt;/item&gt; &lt;item&gt;Saturn&lt;/item&gt; &lt;item&gt;Uranus&lt;/item&gt; &lt;item&gt;Neptune&lt;/item&gt; &lt;/string-array&gt; &lt;/resources&gt; </code></pre> <p>and here logcat</p> <pre><code>Thread [&lt;1&gt; main] (Suspended (exception ArrayIndexOutOfBoundsException)) AlertController$RecycleListView(ViewGroup).getChildAt(int) line: 3065 AlertController$RecycleListView(ListView).layoutChildren() line: 1494 AlertController$RecycleListView(AbsListView).onLayout(boolean, int, int, int, int) line: 1260 AlertController$RecycleListView(View).layout(int, int, int, int) line: 7175 LinearLayout.setChildFrame(View, int, int, int, int) line: 1254 LinearLayout.layoutVertical() line: 1130 LinearLayout.onLayout(boolean, int, int, int, int) line: 1047 LinearLayout(View).layout(int, int, int, int) line: 7175 WeightedLinearLayout(LinearLayout).setChildFrame(View, int, int, int, int) line: 1254 WeightedLinearLayout(LinearLayout).layoutVertical() line: 1130 WeightedLinearLayout(LinearLayout).onLayout(boolean, int, int, int, int) line: 1047 WeightedLinearLayout(View).layout(int, int, int, int) line: 7175 FrameLayout.onLayout(boolean, int, int, int, int) line: 338 FrameLayout(View).layout(int, int, int, int) line: 7175 PhoneWindow$DecorView(FrameLayout).onLayout(boolean, int, int, int, int) line: 338 PhoneWindow$DecorView(View).layout(int, int, int, int) line: 7175 ViewRoot.performTraversals() line: 1140 ViewRoot.handleMessage(Message) line: 1859 ViewRoot(Handler).dispatchMessage(Message) line: 99 Looper.loop() line: 130 ActivityThread.main(String[]) line: 3683 Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method] Method.invoke(Object, Object...) line: 507 ZygoteInit$MethodAndArgsCaller.run() line: 839 ZygoteInit.main(String[]) line: 597 NativeStart.main(String[]) line: not available [native method] </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload