Data not loading into my Spinner
I'm trying to load an array of data into a Spinner component and it's throwing a NullPointerException. The code I'm using is below and it all seems okay.
Spinner spinner = (Spinner) findViewById(R.id.spinner);
ArrayAdapter<?> spin_adapter = ArrayAdapter.createFromResource(
this, R.array.letters_array, android.R.layout.simple_spinner_item);
spin_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(spin_adapter);
The string-array looks like this
<string-array name="letters_array">
<item>A</item>
<item>B</item>
<item>C</item>
<item>D</item>
<item>E</item>
<item>F</item>
<item>G</item>
<item>H</item>
<item>I</item>
<item>J</item>
<item>K</item>
<item>L开发者_JAVA百科</item>
<item>M</item>
<item>N</item>
<item>O</item>
<item>P</item>
<item>Q</item>
<item>R</item>
<item>S</item>
<item>T</item>
<item>U</item>
<item>V</item>
<item>W</item>
<item>X</item>
<item>Y</item>
<item>Z</item>
</string-array>
Is there a limit to the number of items in a Spinner or am I doing something else wrong?
Try this:
ArrayAdapter<CharSequence> spin_adapter = ...
In which xml-File is your Array stored and where is it located?
精彩评论