我想在一个spinner中添加另一个类的list中的items。使用的下面的代码但是给出null pointer exception。
ArrayAdapter<Address> adapter = new ArrayAdapter<Address>(
this,
android.R.layout.simple_spinner_item,
HomePage.NearPlaces
);
adapter.setDropDownViewResource(
android.R.layout.simple_spinner_dropdown_item
);
Place.setAdapter(adapter);
LogCat 输出:
INFO/ActivityManager(96): Starting: Intent { cmp=com.emx.OnDaMove/.SpotMe } from pid 20881
WARN/ActivityManager(96): Activity pause timeout for HistoryRecord{40705eb0 com.emx.OnDaMove/.HomePage}
DEBUG/AndroidRuntime(20881): Shutting down VM
WARN/dalvikvm(20881): threadid=1: thread exiting with uncaught exception (group=0x40015560)
ERROR/AndroidRuntime(20881): FATAL EXCEPTION: main
ERROR/AndroidRuntime(20881): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.emx.OnDaMove/com.emx.OnDaMove.SpotMe}: java.lang.NullPointerException
ERROR/AndroidRuntime(20881): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
ERROR/AndroidRuntime(20881): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
ERROR/AndroidRuntime(20881): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
ERROR/AndroidRuntime(20881): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
ERROR/AndroidRuntime(20881): at android.os.Handler.dispatchMessage(Handler.java:99)
ERROR/AndroidRuntime(20881): at android.os.Looper.loop(Looper.java:130)
ERROR/AndroidRuntime(20881): at android.app.ActivityThread.main(ActivityThread.java:3683)
ERROR/AndroidRuntime(20881): at java.lang.reflect.Method.invokeNative(Native Method)
ERROR/AndroidRuntime(20881): at java.lang.reflect.Method.invoke(Method.java:507)
ERROR/AndroidRuntime(20881): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
ERROR/AndroidRuntime(20881): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
ERROR/AndroidRuntime(20881): at dalvik.system.NativeStart.main(Native Method)
ERROR/AndroidRuntime(20881): Caused by: java.lang.NullPointerException
ERROR/AndroidRuntime(20881): at com.emx.OnDaMove.SpotMe.onCreate(SpotMe.java:42)
ERROR/AndroidRuntime(20881): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
ERROR/AndroidRuntime(20881): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
ERROR/AndroidRuntime(20881): ... 11 more