首页 > 代码库 > android启动时报错Unable to instantiate application xxxx:java.lang.NullPointerException
android启动时报错Unable to instantiate application xxxx:java.lang.NullPointerException
如果程序已经运行,再安装到手机的时候总是报以下错误。而且是在打开特定的Activity的情况下才会报错。
06-26 09:45:16.971: E/AndroidRuntime(29733): java.lang.RuntimeException: Unable to instantiate application com.css.promotiontool.ui.CSSAppliction: java.lang.NullPointerException
06-26 09:45:16.971: E/AndroidRuntime(29733): at android.app.LoadedApk.makeApplication(LoadedApk.java:508)
06-26 09:45:16.971: E/AndroidRuntime(29733): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4245)
06-26 09:45:16.971: E/AndroidRuntime(29733): at android.app.ActivityThread.access$1400(ActivityThread.java:131)
06-26 09:45:16.971: E/AndroidRuntime(29733): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1288)
06-26 09:45:16.971: E/AndroidRuntime(29733): at android.os.Handler.dispatchMessage(Handler.java:99)
06-26 09:45:16.971: E/AndroidRuntime(29733): at android.os.Looper.loop(Looper.java:137)
06-26 09:45:16.971: E/AndroidRuntime(29733): at android.app.ActivityThread.main(ActivityThread.java:4866)
06-26 09:45:16.971: E/AndroidRuntime(29733): at java.lang.reflect.Method.invokeNative(Native Method)
06-26 09:45:16.971: E/AndroidRuntime(29733): at java.lang.reflect.Method.invoke(Method.java:511)
06-26 09:45:16.971: E/AndroidRuntime(29733): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
06-26 09:45:16.971: E/AndroidRuntime(29733): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
06-26 09:45:16.971: E/AndroidRuntime(29733): at dalvik.system.NativeStart.main(Native Method)
06-26 09:45:16.971: E/AndroidRuntime(29733): Caused by: java.lang.NullPointerException
06-26 09:45:16.971: E/AndroidRuntime(29733): at android.app.LoadedApk.initializeJavaContextClassLoader(LoadedApk.java:384)
06-26 09:45:16.971: E/AndroidRuntime(29733): at android.app.LoadedApk.getClassLoader(LoadedApk.java:327)
06-26 09:45:16.971: E/AndroidRuntime(29733): at android.app.LoadedApk.makeApplication(LoadedApk.java:500)
06-26 09:45:16.971: E/AndroidRuntime(29733): ... 11 more
这个问题困扰了好久,网上也查了好多次,但是都没有解决问题。最后从引用资源文件入手,发现是特定的activity标签下引用了资源文件:
<activity
android:name=xxxx
android:label="@string/app_name"/>
删掉引用资源文件就可以了,由于时间问题具体原因未深究。