1、java.lang.NullPointerException: Attempt to invoke virtual method ‘android.content.res.AssetManager android.content.res.Resources.getAssets()’ on a null object reference抛出这个错误是在安装apk的时候就黑屏了,刚开始百思不得其解,明明还没有调用getAssets()就一直抛出这个异常,各种加日志加注释没找到问题所在。最后既然提示这个android.content.res.Resources为空,就在Application的onCreate()加判断发现getResource确实为空
RuntimeException: Unable to start activity ComponentInfo: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.AssetManager android.content.res.Resources.getAssets()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:902)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:697)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.AssetManager android.content.res.Resources.getAssets()' on a null object reference
at android.app.LoadedApk.getAssets(LoadedApk.java:528)
at android.app.LoadedApk.makeApplication(LoadedApk.java:584)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2243)
... 10 more
//解决方法:在Application的onCreate()加判断,getResource()为空的时候杀死当前进程
if (null == getResources())