我試圖運行我的應用程序,但它在到達onCreate()方法之前崩潰。我是新來的android和eclipse,所以我甚至不知道從哪裏開始尋找錯誤。Eclipse錯誤:無法實例化活動
這就是錯誤消息形式的logcat:
11-22 21:06:59.787: WARN/dalvikvm(433): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
11-22 21:07:01.468: ERROR/AndroidRuntime(433): FATAL EXCEPTION: main
11-22 21:07:01.468: ERROR/AndroidRuntime(433): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.app/com.example.app.HelloActivity}: java.lang.NullPointerException
11-22 21:07:01.468: ERROR/AndroidRuntime(433): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
11-22 21:07:01.468: ERROR/AndroidRuntime(433): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
11-22 21:07:01.468: ERROR/AndroidRuntime(433): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
11-22 21:07:01.468: ERROR/AndroidRuntime(433): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
11-22 21:07:01.468: ERROR/AndroidRuntime(433): at android.os.Handler.dispatchMessage(Handler.java:99)
11-22 21:07:01.468: ERROR/AndroidRuntime(433): at android.os.Looper.loop(Looper.java:123)
11-22 21:07:01.468: ERROR/AndroidRuntime(433): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-22 21:07:01.468: ERROR/AndroidRuntime(433): at java.lang.reflect.Method.invokeNative(Native Method)
11-22 21:07:01.468: ERROR/AndroidRuntime(433): at java.lang.reflect.Method.invoke(Method.java:521)
11-22 21:07:01.468: ERROR/AndroidRuntime(433): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-22 21:07:01.468: ERROR/AndroidRuntime(433): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-22 21:07:01.468: ERROR/AndroidRuntime(433): at dalvik.system.NativeStart.main(Native Method)
11-22 21:07:01.468: ERROR/AndroidRuntime(433): Caused by: java.lang.NullPointerException
11-22 21:07:01.468: ERROR/AndroidRuntime(433): at android.content.ContextWrapper.getSharedPreferences(ContextWrapper.java:146)
11-22 21:07:01.468: ERROR/AndroidRuntime(433): at com.example.app.HelloActivity.<init>(HelloActivity.java:51)
11-22 21:07:01.468: ERROR/AndroidRuntime(433): at java.lang.Class.newInstanceImpl(Native Method)
11-22 21:07:01.468: ERROR/AndroidRuntime(433): at java.lang.Class.newInstance(Class.java:1429)
11-22 21:07:01.468: ERROR/AndroidRuntime(433): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
11-22 21:07:01.468: ERROR/AndroidRuntime(433): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
11-22 21:07:01.468: ERROR/AndroidRuntime(433): ... 11 more
嗯...你在第51行的HelloActivity中有一個空指針異常,所以我建議看看那裏。 – MrZander
如果您仍然難以編輯您的問題以包含HelloActivity的代碼。 – Krylez
是的,那一行實際告訴你的是異常的行號:at com.example.app.HelloActivity。(HelloActivity.java:51)表示第51行,某些內容爲空。 –
Jack