我想在我的应用程序中使用 Spinner。Spinner 的上下文(项目)取决于在应用程序设置中完成的用户首选项。
我创建了没有项目的 Spinner。加载应用程序后,微调器有一个条目。要获取条目,用户必须转到菜单并加载图像。基于此,项目被加载到字符串数组中。这个字符串数组将被移交给适配器。见代码:
List<String> als = new ArrayList<String>();
als = Arrays.asList(Data.getfloornames());
adapter = new ArrayAdapter<String>(this, R.array.flooritem, als);
adapter.notifyDataSetChanged();
floornum.setAdapter(adapter);
完成后。用户将返回到菜单设置。在菜单设置中单击设备的返回按钮,导致应用程序中止。
Error from Logcat is FATAL Exception: main.
05-16 15:12:43.193: E/AndroidRuntime(9128): android.content.res.Resources$NotFoundException: Resource ID #0x7f060002
05-16 15:12:43.193: E/AndroidRuntime(9128): at android.content.res.Resources.getValue(Resources.java:1014)
05-16 15:12:43.193: E/AndroidRuntime(9128): at android.content.res.Resources.loadXmlResourceParser(Resources.java:2139)
05-16 15:12:43.193: E/AndroidRuntime(9128): at android.content.res.Resources.getLayout(Resources.java:853)
05-16 15:12:43.193: E/AndroidRuntime(9128): at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
05-16 15:12:43.193: E/AndroidRuntime(9128): at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:371)
05-16 15:12:43.193: E/AndroidRuntime(9128): at android.widget.ArrayAdapter.getView(ArrayAdapter.java:362)
05-16 15:12:43.193: E/AndroidRuntime(9128): at android.widget.AbsSpinner.onMeasure(AbsSpinner.java:193)
05-16 15:12:43.193: E/AndroidRuntime(9128): at android.widget.Spinner.onMeasure(Spinner.java:439)
05-16 15:12:43.193: E/AndroidRuntime(9128): at android.view.View.measure(View.java:15518)
05-16 15:12:43.193: E/AndroidRuntime(9128): at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:681)
05-16 15:12:43.193: E/AndroidRuntime(9128): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
05-16 15:12:43.193: E/AndroidRuntime(9128): at android.view.View.measure(View.java:15518)
05-16 15:12:43.193: E/AndroidRuntime(9128): at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:681)
05-16 15:12:43.193: E/AndroidRuntime(9128): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
05-16 15:12:43.193: E/AndroidRuntime(9128): at android.view.View.measure(View.java:15518)
05-16 15:12:43.193: E/AndroidRuntime(9128): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
05-16 15:12:43.193: E/AndroidRuntime(9128): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
05-16 15:12:43.193: E/AndroidRuntime(9128): at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
05-16 15:12:43.193: E/AndroidRuntime(9128): at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
05-16 15:12:43.193: E/AndroidRuntime(9128): at android.view.View.measure(View.java:15518)
05-16 15:12:43.193: E/AndroidRuntime(9128): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
05-16 15:12:43.193: E/AndroidRuntime(9128): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
05-16 15:12:43.193: E/AndroidRuntime(9128): at android.view.View.measure(View.java:15518)
05-16 15:12:43.193: E/AndroidRuntime(9128): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
05-16 15:12:43.193: E/AndroidRuntime(9128): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
05-16 15:12:43.193: E/AndroidRuntime(9128): at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
05-16 15:12:43.193: E/AndroidRuntime(9128): at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
05-16 15:12:43.193: E/AndroidRuntime(9128): at android.view.View.measure(View.java:15518)
05-16 15:12:43.193: E/AndroidRuntime(9128): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
05-16 15:12:43.193: E/AndroidRuntime(9128): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
05-16 15:12:43.193: E/AndroidRuntime(9128): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2176)
05-16 15:12:43.193: E/AndroidRuntime(9128): at android.view.View.measure(View.java:15518)
05-16 15:12:43.193: E/AndroidRuntime(9128): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1874)
05-16 15:12:43.193: E/AndroidRuntime(9128): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1089)
05-16 15:12:43.193: E/AndroidRuntime(9128): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1265)
05-16 15:12:43.193: E/AndroidRuntime(9128): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
05-16 15:12:43.193: E/AndroidRuntime(9128): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
05-16 15:12:43.193: E/AndroidRuntime(9128): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
05-16 15:12:43.193: E/AndroidRuntime(9128): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
05-16 15:12:43.193: E/AndroidRuntime(9128): at android.view.Choreographer.doFrame(Choreographer.java:532)
05-16 15:12:43.193: E/AndroidRuntime(9128): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
05-16 15:12:43.193: E/AndroidRuntime(9128): at android.os.Handler.handleCallback(Handler.java:725)
05-16 15:12:43.193: E/AndroidRuntime(9128): at android.os.Handler.dispatchMessage(Handler.java:92)
05-16 15:12:43.193: E/AndroidRuntime(9128): at android.os.Looper.loop(Looper.java:137)
05-16 15:12:43.193: E/AndroidRuntime(9128): at android.app.ActivityThread.main(ActivityThread.java:5041)
05-16 15:12:43.193: E/AndroidRuntime(9128): at java.lang.reflect.Method.invokeNative(Native Method)
05-16 15:12:43.193: E/AndroidRuntime(9128): at java.lang.reflect.Method.invoke(Method.java:511)
05-16 15:12:43.193: E/AndroidRuntime(9128): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-16 15:12:43.193: E/AndroidRuntime(9128): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-16 15:12:43.193: E/AndroidRuntime(9128): at dalvik.system.NativeStart.main(Native Method)
我究竟做错了什么?无法在应用程序的菜单设置中设置 Spinner Items 吗?