Spinner cannot load an integer array?

Posted by Adam on Stack Overflow See other posts from Stack Overflow or by Adam
Published on 2010-04-19T23:47:46Z Indexed on 2010/04/19 23:53 UTC
Read the original article Hit count: 424

I have an application, which has a Spinner that I want populated with some numbers (4,8,12,16). I created an integer-array object in strings.xml with the items mentioned above, set the entries of the Spinner to the integer-array, and when I run the app I get:

04-19 23:38:48.016: ERROR/AndroidRuntime(10193): java.lang.NullPointerException
04-19 23:38:48.016: ERROR/AndroidRuntime(10193):     at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:355)
04-19 23:38:48.016: ERROR/AndroidRuntime(10193):     at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323)
04-19 23:38:48.016: ERROR/AndroidRuntime(10193):     at android.widget.AbsSpinner.onMeasure(AbsSpinner.java:198)
04-19 23:38:48.016: ERROR/AndroidRuntime(10193):     at android.view.View.measure(View.java:7965)
04-19 23:38:48.016: ERROR/AndroidRuntime(10193):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2989)
04-19 23:38:48.016: ERROR/AndroidRuntime(10193):     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:888)
04-19 23:38:48.016: ERROR/AndroidRuntime(10193):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:350)
04-19 23:38:48.016: ERROR/AndroidRuntime(10193):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:278)
04-19 23:38:48.016: ERROR/AndroidRuntime(10193):     at android.view.View.measure(View.java:7965)
04-19 23:38:48.016: ERROR/AndroidRuntime(10193):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2989)
04-19 23:38:48.016: ERROR/AndroidRuntime(10193):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
04-19 23:38:48.016: ERROR/AndroidRuntime(10193):     at android.view.View.measure(View.java:7965)
04-19 23:38:48.016: ERROR/AndroidRuntime(10193):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:464)
04-19 23:38:48.016: ERROR/AndroidRuntime(10193):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:278)
04-19 23:38:48.016: ERROR/AndroidRuntime(10193):     at android.view.View.measure(View.java:7965)
04-19 23:38:48.016: ERROR/AndroidRuntime(10193):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2989)
04-19 23:38:48.016: ERROR/AndroidRuntime(10193):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
04-19 23:38:48.016: ERROR/AndroidRuntime(10193):     at android.view.View.measure(View.java:7965)
04-19 23:38:48.016: ERROR/AndroidRuntime(10193):     at android.view.ViewRoot.performTraversals(ViewRoot.java:763)
04-19 23:38:48.016: ERROR/AndroidRuntime(10193):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1632)
04-19 23:38:48.016: ERROR/AndroidRuntime(10193):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-19 23:38:48.016: ERROR/AndroidRuntime(10193):     at android.os.Looper.loop(Looper.java:123)
04-19 23:38:48.016: ERROR/AndroidRuntime(10193):     at android.app.ActivityThread.main(ActivityThread.java:4310)
04-19 23:38:48.016: ERROR/AndroidRuntime(10193):     at java.lang.reflect.Method.invokeNative(Native Method)
04-19 23:38:48.016: ERROR/AndroidRuntime(10193):     at java.lang.reflect.Method.invoke(Method.java:521)
04-19 23:38:48.016: ERROR/AndroidRuntime(10193):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
04-19 23:38:48.016: ERROR/AndroidRuntime(10193):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
04-19 23:38:48.016: ERROR/AndroidRuntime(10193):     at dalvik.system.NativeStart.main(Native Method)

As soon as I changed the array to a string-array, this works fine. Is this normal? I realize that I can (and will) just convert the string array values to an int, but it seems weird that I have to.

Thanks!

© Stack Overflow or respective owner

Related posts about android

Related posts about android-sdk