-1
我真的很陌生,所以有可能我的錯是非常愚蠢的..但是我的應用程序崩潰沒有任何可見的原因。Android應用程序沒有任何原因崩潰
我logcat的輸出:
05-25 19:15:25.656: D/dalvikvm(25858): threadid=1: still suspended after undo (sc=1 dc=1)
05-25 19:15:30.171: D/AndroidRuntime(25858): Shutting down VM
05-25 19:15:30.171: W/dalvikvm(25858): threadid=1: thread exiting with uncaught exception (group=0x40e1aa08)
05-25 19:15:30.251: E/AndroidRuntime(25858): FATAL EXCEPTION: main
05-25 19:15:30.251: E/AndroidRuntime(25858): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{de.mo.securegate/de.mo.securegate.MainActivity}: java.lang.NullPointerException
05-25 19:15:30.251: E/AndroidRuntime(25858): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2228)
05-25 19:15:30.251: E/AndroidRuntime(25858): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2362)
05-25 19:15:30.251: E/AndroidRuntime(25858): at android.app.ActivityThread.access$600(ActivityThread.java:156)
05-25 19:15:30.251: E/AndroidRuntime(25858): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1250)
05-25 19:15:30.251: E/AndroidRuntime(25858): at android.os.Handler.dispatchMessage(Handler.java:99)
05-25 19:15:30.251: E/AndroidRuntime(25858): at android.os.Looper.loop(Looper.java:137)
05-25 19:15:30.251: E/AndroidRuntime(25858): at android.app.ActivityThread.main(ActivityThread.java:5229)
05-25 19:15:30.251: E/AndroidRuntime(25858): at java.lang.reflect.Method.invokeNative(Native Method)
05-25 19:15:30.251: E/AndroidRuntime(25858): at java.lang.reflect.Method.invoke(Method.java:525)
05-25 19:15:30.251: E/AndroidRuntime(25858): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:799)
05-25 19:15:30.251: E/AndroidRuntime(25858): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
05-25 19:15:30.251: E/AndroidRuntime(25858): at dalvik.system.NativeStart.main(Native Method)
05-25 19:15:30.251: E/AndroidRuntime(25858): Caused by: java.lang.NullPointerException
05-25 19:15:30.251: E/AndroidRuntime(25858): at android.content.ContextWrapper.getSharedPreferences(ContextWrapper.java:161)
05-25 19:15:30.251: E/AndroidRuntime(25858): at de.mo.securegate.MainActivity.<init>(MainActivity.java:28)
05-25 19:15:30.251: E/AndroidRuntime(25858): at java.lang.Class.newInstanceImpl(Native Method)
05-25 19:15:30.251: E/AndroidRuntime(25858): at java.lang.Class.newInstance(Class.java:1319)
05-25 19:15:30.251: E/AndroidRuntime(25858): at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
05-25 19:15:30.251: E/AndroidRuntime(25858): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2219)
05-25 19:15:30.251: E/AndroidRuntime(25858): ... 11 more
什麼想法?
我所知道的總是有一個原因。在實例化活動時看起來像是一個NullPointerExeption。你有沒有在ContextWrapper.java中檢查第161行? –
行號28在MainActivity導致NPE。炫耀這條線。 – Sunny
您可能試圖在方法外部獲得'SharedPreferences'。發佈代碼 – codeMagic