开发者

Error while calling an array resource with item "in"

开发者 https://www.devze.com 2023-03-22 22:33 出处:网络
I am trying to load an array for my list preference. It is for height and so my values are \'in\' for inches and \'cm\' for centimeters. The preference list dialog crashes as soon as I try to open the

I am trying to load an array for my list preference. It is for height and so my values are 'in' for inches and 'cm' for centimeters. The preference list dialog crashes as soon as I try to open the dialog. When I change it to any string other than the item 'in' it works. Does anyone know why this might be happening?

Edit:

Here is my array. I did not define it as string array.

<array name="len开发者_StackOverflow中文版gth_units">
    <item>in</item>
    <item>cm</item>
</array>

Here is the stacktrace

> W/dalvikvm(18013): threadid=1: thread exiting with uncaught exception
> (group=0x400259f8) E/AndroidRuntime(18013): FATAL EXCEPTION: main
> E/AndroidRuntime(18013): java.lang.NullPointerException
> E/AndroidRuntime(18013):  at
> android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:355)
> E/AndroidRuntime(18013):  at
> android.widget.ArrayAdapter.getView(ArrayAdapter.java:323)
> E/AndroidRuntime(18013):  at
> android.widget.AbsListView.obtainView(AbsListView.java:1315)
> E/AndroidRuntime(18013):  at
> android.widget.ListView.measureHeightOfChildren(ListView.java:1198)
> E/AndroidRuntime(18013):  at
> android.widget.ListView.onMeasure(ListView.java:1109)
> E/AndroidRuntime(18013):  at android.view.View.measure(View.java:8172)
> E/AndroidRuntime(18013):  at
> android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3140)
> E/AndroidRuntime(18013):  at
> android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
> E/AndroidRuntime(18013):  at
> android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
> E/AndroidRuntime(18013):  at
> android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
> E/AndroidRuntime(18013):  at android.view.View.measure(View.java:8172)
> E/AndroidRuntime(18013):  at
> android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3140)
> E/AndroidRuntime(18013):  at
> android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
> E/AndroidRuntime(18013):  at
> android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
> E/AndroidRuntime(18013):  at
> android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
> E/AndroidRuntime(18013):  at
> com.android.internal.widget.WeightedLinearLayout.onMeasure(WeightedLinearLayout.java:60)
> E/AndroidRuntime(18013):  at android.view.View.measure(View.java:8172)
> E/AndroidRuntime(18013):  at
> android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3140)
> E/AndroidRuntime(18013):  at
> android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
> E/AndroidRuntime(18013):  at android.view.View.measure(View.java:8172)
> E/AndroidRuntime(18013):  at
> android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3140)
> E/AndroidRuntime(18013):  at
> android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
> E/AndroidRuntime(18013):  at android.view.View.measure(View.java:8172)
> E/AndroidRuntime(18013):  at
> android.view.ViewRoot.performTraversals(ViewRoot.java:805)
> E/AndroidRuntime(18013):  at
> android.view.ViewRoot.handleMessage(ViewRoot.java:1744)
> E/AndroidRuntime(18013):  at
> android.os.Handler.dispatchMessage(Handler.java:99)
> E/AndroidRuntime(18013):  at android.os.Looper.loop(Looper.java:144)
> E/AndroidRuntime(18013):  at
> android.app.ActivityThread.main(ActivityThread.java:4937)
> E/AndroidRuntime(18013):  at
> java.lang.reflect.Method.invokeNative(Native Method)
> E/AndroidRuntime(18013):  at
> java.lang.reflect.Method.invoke(Method.java:521)
> E/AndroidRuntime(18013):  at
> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
> E/AndroidRuntime(18013):  at
> com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
> E/AndroidRuntime(18013):  at dalvik.system.NativeStart.main(Native
> Method)


Like CommonsWare said in the comments above, only is supported by a ListPreference. Everything worked fine after I changed it to string-array.

I am just putting it here since he/she did not put it as an answer.

0

精彩评论

暂无评论...
验证码 换一张
取 消