应用程序与NullPointerException一起崩溃

时间:2014-07-02 06:20:50

标签: android crash

该应用程序在前一天工作正常,但是当我今天尝试启动它时它一直在崩溃。代码中没有发现错误。 这是下面的日志猫:

07-02 14:08:43.765: D/AndroidRuntime(16274): Shutting down VM
07-02 14:08:43.765: W/dalvikvm(16274): threadid=1: thread exiting with uncaught exception (group=0x41249930)
07-02 14:08:43.770: E/AndroidRuntime(16274): FATAL EXCEPTION: main
07-02 14:08:43.770: E/AndroidRuntime(16274): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.myexerciseplanner/com.example.myexerciseplanner.MainActivity}: java.lang.NullPointerException
07-02 14:08:43.770: E/AndroidRuntime(16274):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
07-02 14:08:43.770: E/AndroidRuntime(16274):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2299)
07-02 14:08:43.770: E/AndroidRuntime(16274):     at android.app.ActivityThread.access$700(ActivityThread.java:154)
07-02 14:08:43.770: E/AndroidRuntime(16274):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284)
07-02 14:08:43.770: E/AndroidRuntime(16274):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-02 14:08:43.770: E/AndroidRuntime(16274):     at android.os.Looper.loop(Looper.java:137)
07-02 14:08:43.770: E/AndroidRuntime(16274):     at android.app.ActivityThread.main(ActivityThread.java:5306)
07-02 14:08:43.770: E/AndroidRuntime(16274):     at java.lang.reflect.Method.invokeNative(Native Method)
07-02 14:08:43.770: E/AndroidRuntime(16274):     at java.lang.reflect.Method.invoke(Method.java:511)
07-02 14:08:43.770: E/AndroidRuntime(16274):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
07-02 14:08:43.770: E/AndroidRuntime(16274):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
07-02 14:08:43.770: E/AndroidRuntime(16274):     at dalvik.system.NativeStart.main(Native Method)
07-02 14:08:43.770: E/AndroidRuntime(16274): Caused by: java.lang.NullPointerException
07-02 14:08:43.770: E/AndroidRuntime(16274):     at android.app.Activity.findViewById(Activity.java:1886)
07-02 14:08:43.770: E/AndroidRuntime(16274):     at com.example.myexerciseplanner.MainActivity.(MainActivity.java:58)
07-02 14:08:43.770: E/AndroidRuntime(16274):     at java.lang.Class.newInstanceImpl(Native Method)
07-02 14:08:43.770: E/AndroidRuntime(16274):     at java.lang.Class.newInstance(Class.java:1319)
07-02 14:08:43.770: E/AndroidRuntime(16274):     at android.app.Instrumentation.newActivity(Instrumentation.java:1071)
07-02 14:08:43.770: E/AndroidRuntime(16274):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2166)
07-02 14:08:43.770: E/AndroidRuntime(16274):     ... 11 more

1 个答案:

答案 0 :(得分:0)

我认为您在 setContentView 之前使用了 findViewById 。但是你需要发布你的代码。