当Android应用程序进程被杀时,应用程序在恢复时崩溃

时间:2016-11-02 18:46:16

标签: android nullpointerexception onresume

当我的应用程序被杀,因为其他应用程序需要资源而我返回应用程序时,我收到NullPointerException。我试图通过在onResume:

中检查这个来解决这个问题
@Override
protected void onResume() {
    super.onResume();
    if (aanvraag == null) {
        getSupportFragmentManager().beginTransaction().add(R.id.pager, new StartFragment()).commit();
    }
}

不幸的是,这似乎不起作用。这个想法是应用程序的整个工作流程重新启动(通过启动我的StartFragment)。

有什么建议吗?

修改

应用程序在活动中的一个片段中崩溃。正在使用对象aanvraag的地方。

logcat的:

Java.lang.RuntimeException: Unable to start activity ComponentInfo{nl.emconsult.wbso/nl.emconsult.wbso.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2186)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2236)
at android.app.ActivityThread.access$600(ActivityThread.java:145)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1238)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5099)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:803)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:570)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at nl.emconsult.wbso.fragments.ResultatenFragment.vulVelden(ResultatenFragment.java:138)
at nl.emconsult.wbso.fragments.ResultatenFragment.onCreateView(ResultatenFragment.java:61)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1234)
at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:2046)
at android.support.v4.app.FragmentController.dispatchActivityCreated(FragmentController.java:174)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:598)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1165)
at android.app.Activity.performStart(Activity.java:5127)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
... 11 more

Resultatenfragment(或至少从所有不相关的细节中删除):

public class ResultatenFragment extends Fragment {

public ResultatenFragment() {
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    final View rootView= inflater.inflate(R.layout.resultaten_fragment, container, false);

    boolean someVariable = vulVelden(rootView);

    return rootView;

}

    private boolean vulVelden(View rootView) {
    //Perform some calculations, store some and display some values and return true if everything works out allright. 
    aanvraag.doSomething(); //This is ResultatenFragment.java:138, where I get the NullPointerException 
    return (true);
    }

}

0 个答案:

没有答案