问题描述
- 用Eclipse开发android 应用时,在logcat里出现了fatal exception :main ,怎么解决?
-
logcat 如下:07-29 13:44:35.140: E/AndroidRuntime(375): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.zhinengdiancan/com.zhinengdiancan.MainActivity}: java.lang.NullPointerException
07-29 13:44:35.140: E/AndroidRuntime(375): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1736)
07-29 13:44:35.140: E/AndroidRuntime(375): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1752)
07-29 13:44:35.140: E/AndroidRuntime(375): at android.app.ActivityThread.access$1500(ActivityThread.java:123)
07-29 13:44:35.140: E/AndroidRuntime(375): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:993)
07-29 13:44:35.140: E/AndroidRuntime(375): at android.os.Handler.dispatchMessage(Handler.java:99)
07-29 13:44:35.140: E/AndroidRuntime(375): at android.os.Looper.loop(Looper.java:126)
07-29 13:44:35.140: E/AndroidRuntime(375): at android.app.ActivityThread.main(ActivityThread.java:3997)
07-29 13:44:35.140: E/AndroidRuntime(375): at java.lang.reflect.Method.invokeNative(Native Method)
07-29 13:44:35.140: E/AndroidRuntime(375): at java.lang.reflect.Method.invoke(Method.java:491)
07-29 13:44:35.140: E/AndroidRuntime(375): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
07-29 13:44:35.140: E/AndroidRuntime(375): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
07-29 13:44:35.140: E/AndroidRuntime(375): at dalvik.system.NativeStart.main(Native Method)
07-29 13:44:35.140: E/AndroidRuntime(375): Caused by: java.lang.NullPointerException
07-29 13:44:35.140: E/AndroidRuntime(375): at com.zhinengdiancan.MainActivity.LoadUserdata(MainActivity.java:222)
07-29 13:44:35.140: E/AndroidRuntime(375): at com.zhinengdiancan.MainActivity.onCreate(MainActivity.java:67)
07-29 13:44:35.140: E/AndroidRuntime(375): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
07-29 13:44:35.140: E/AndroidRuntime(375): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1700)
07-29 13:44:35.140: E/AndroidRuntime(375): ... 11 more
解决方案
com.zhinengdiancan.MainActivity.LoadUserdata(MainActivity.java:222)
从错误来看是在MainActivity中的222行的LoadUserdata方法出现了空指针,你检查下那边的值
解决方案二:
检查下Activity onCreate里面的方法有没有写错,不行clean下,还不行,重启eclipse试试