android进程被杀死后在启动异常

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.****.****/com.***.*****.activity.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object android.content.Context.getSystemService(java.lang.String)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2519)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2586)
at android.app.ActivityThread.access$900(ActivityThread.java:163)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1462)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5574)
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:962)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object android.content.Context.getSystemService(java.lang.String)' on a null object reference
at android.app.Dialog.(Dialog.java:164)
at android.app.Dialog.(Dialog.java:148)
at com.apyf.asx_js.view.ShapeLoadingDialog.init(ShapeLoadingDialog.java:28)
at com.apyf.asx_js.view.ShapeLoadingDialog.(ShapeLoadingDialog.java:24)
at com.apyf.asx_js.fragment.ConsultationFragment.data(ConsultationFragment.java:103)
at com.apyf.asx_js.activity.MainActivity.toolbarInit(MainActivity.java:251)
at com.apyf.asx_js.activity.MainActivity.onPageSelected(MainActivity.java:219)
at android.support.v4.view.ViewPager.dispatchOnPageSelected(ViewPager.java:1961)
at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:664)
at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:630)
at android.support.v4.view.ViewPager.onRestoreInstanceState(ViewPager.java:1482)
at android.view.View.dispatchRestoreInstanceState(View.java:13870)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2891)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2897)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2897)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2897)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2897)
at android.view.View.restoreHierarchyState(View.java:13848)
at com.android.internal.policy.impl.PhoneWindow.restoreHierarchyState(PhoneWindow.java:2075)
at android.app.Activity.onRestoreInstanceState(Activity.java:1053)
at android.app.Activity.performRestoreInstanceState(Activity.java:1008)
at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1203)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2492)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2586) 
at android.app.ActivityThread.access$900(ActivityThread.java:163) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1462) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5574) 
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:962) 
1. at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757) 
进程被杀了后就按图标在打开项目就报错了········求大神给出解决方法

2个回答

空指针异常 已经很明显告诉你了 就是getSystemService()这里面 所引用的对象为空 你仔细排查一下既可以了 应该是还没有创建就被你引用了

sinat_25378595
sinat_25378595 感谢给的想法 问题解决了,不保存Fragment的状态就好了。。。
接近 2 年之前 回复

貌似是上下文的原因,你如果传的是application的上下文,没有activity的引用,需要在打开activity时添加一个Task,具体可以百度一下,很常见的

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!