我在开始一项活动时遇到了一个奇怪的问题。我可以使用菜单从菜单启动它
Intent intent = new Intent(this,SplashScreen.class);
this.startActivity(intent);
但如果我尝试从 ListView.setOnItemClickListener 启动它,它会崩溃。但是我尝试了各种方法,结果是一样的(我想开始的活动是一个空白屏幕,所以没什么可疑的)。这是当前的代码...
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
startActivity(new Intent(getBaseContext(), SplashScreen.class));
}});
活动被添加到清单中......并且主类扩展了活动。
日志猫
02-23 17:17:11.070: W/dalvikvm(3200): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
02-23 17:17:11.248: E/AndroidRuntime(3200): FATAL EXCEPTION: main
02-23 17:17:11.248: E/AndroidRuntime(3200): java.lang.RuntimeException: Unable to start activity ComponentInfo{ro.pca.rentme/ro.pca.rentme.SplashScreen}: java.lang.NullPointerException
02-23 17:17:11.248: E/AndroidRuntime(3200): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
02-23 17:17:11.248: E/AndroidRuntime(3200): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
02-23 17:17:11.248: E/AndroidRuntime(3200): at android.app.ActivityThread.access$600(ActivityThread.java:130)
02-23 17:17:11.248: E/AndroidRuntime(3200): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
02-23 17:17:11.248: E/AndroidRuntime(3200): at android.os.Handler.dispatchMessage(Handler.java:99)
02-23 17:17:11.248: E/AndroidRuntime(3200): at android.os.Looper.loop(Looper.java:137)
02-23 17:17:11.248: E/AndroidRuntime(3200): at android.app.ActivityThread.main(ActivityThread.java:4745)
02-23 17:17:11.248: E/AndroidRuntime(3200): at java.lang.reflect.Method.invokeNative(Native Method)
02-23 17:17:11.248: E/AndroidRuntime(3200): at java.lang.reflect.Method.invoke(Method.java:511)
02-23 17:17:11.248: E/AndroidRuntime(3200): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
02-23 17:17:11.248: E/AndroidRuntime(3200): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
02-23 17:17:11.248: E/AndroidRuntime(3200): at dalvik.system.NativeStart.main(Native Method)
02-23 17:17:11.248: E/AndroidRuntime(3200): Caused by: java.lang.NullPointerException
02-23 17:17:11.248: E/AndroidRuntime(3200): at ro.pca.rentme.SplashScreen.onCreate(SplashScreen.java:46)
02-23 17:17:11.248: E/AndroidRuntime(3200): at android.app.Activity.performCreate(Activity.java:5008)
02-23 17:17:11.248: E/AndroidRuntime(3200): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
02-23 17:17:11.248: E/AndroidRuntime(3200): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
02-23 17:17:11.248: E/AndroidRuntime(3200): ... 11 more