我在我的应用程序中定义了一个微调器,它在主要活动开始时加载。该活动成功加载,并使用来自另一个类的字符串数组的值加载微调器。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Spinner spinner = (Spinner) findViewById(R.id.spinner);
AnotherClass ac = new AnotherClass();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, ac.array);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
}
单击微调器时,应用程序崩溃并显示以下跟踪:
02-02 15:14:15.947: E/AndroidRuntime(1619): FATAL EXCEPTION: main
02-02 15:14:15.947: E/AndroidRuntime(1619): java.lang.NullPointerException
02-02 15:14:15.947: E/AndroidRuntime(1619): at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:394)
02-02 15:14:15.947: E/AndroidRuntime(1619): at android.widget.ArrayAdapter.getDropDownView(ArrayAdapter.java:415)
02-02 15:14:15.947: E/AndroidRuntime(1619): at android.widget.Spinner$DropDownAdapter.getDropDownView(Spinner.java:569)
02-02 15:14:15.947: E/AndroidRuntime(1619): at android.widget.Spinner$DropDownAdapter.getView(Spinner.java:565)
02-02 15:14:15.947: E/AndroidRuntime(1619): at android.widget.Spinner.measureContentWidth(Spinner.java:513)
02-02 15:14:15.947: E/AndroidRuntime(1619): at android.widget.Spinner$DropdownPopup.show(Spinner.java:739)
02-02 15:14:15.947: E/AndroidRuntime(1619): at android.widget.Spinner.performClick(Spinner.java:453)
02-02 15:14:15.947: E/AndroidRuntime(1619): at android.view.View$PerformClick.run(View.java:14105)
02-02 15:14:15.947: E/AndroidRuntime(1619): at android.os.Handler.handleCallback(Handler.java:605)
02-02 15:14:15.947: E/AndroidRuntime(1619): at android.os.Handler.dispatchMessage(Handler.java:92)
02-02 15:14:15.947: E/AndroidRuntime(1619): at android.os.Looper.loop(Looper.java:137)
02-02 15:14:15.947: E/AndroidRuntime(1619): at android.app.ActivityThread.main(ActivityThread.java:4424)
02-02 15:14:15.947: E/AndroidRuntime(1619): at java.lang.reflect.Method.invokeNative(Native Method)
02-02 15:14:15.947: E/AndroidRuntime(1619): at java.lang.reflect.Method.invoke(Method.java:511)
02-02 15:14:15.947: E/AndroidRuntime(1619): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
02-02 15:14:15.947: E/AndroidRuntime(1619): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
02-02 15:14:15.947: E/AndroidRuntime(1619): at dalvik.system.NativeStart.main(Native Method)
关于如何解决这个问题的任何建议?
谢谢。