Android: NullPointerException at DialogFragment.dismissInternal at DialogFragment.dismissAllow
Asked Answered
I

2

12

Crash app when show ProgressDialog. I'm testing on my phone with a slide-out keyboard. When dialog is show I slide keyboard and app crashes.

public static class ProgressDialogFragment extends DialogFragment
{

    public ProgressDialogFragment()
    {
        super();
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState)
    {
        final ProgressDialog dialog = new ProgressDialog(getActivity());
        dialog.setMessage(getString(R.string.dlg_progress_title));
        dialog.setIndeterminate(true);
        dialog.setCancelable(false);
        return dialog;
    }

    @Override
    public void show(FragmentManager manager, String tag)
    {
        try
        {
            super.show(manager, tag);
        }
        catch (IllegalStateException e)
        {
            Log.d(TAG, e.getMessage());
        }
    }

}

Crash log:

> 04-25 20:49:46.999: E/AndroidRuntime(7904): FATAL EXCEPTION: main
04-25 20:49:46.999: E/AndroidRuntime(7904): java.lang.NullPointerException
04-25 20:49:46.999: E/AndroidRuntime(7904):     at android.support.v4.app.DialogFragment.dismissInternal(DialogFragment.java:184)
04-25 20:49:46.999: E/AndroidRuntime(7904):     at android.support.v4.app.DialogFragment.dismissAllowingStateLoss(DialogFragment.java:165)
04-25 20:49:46.999: E/AndroidRuntime(7904):     at com.fisherman.activity.HomeActivity$2.onPostExecute(HomeActivity.java:268)
04-25 20:49:46.999: E/AndroidRuntime(7904):     at com.fisherman.activity.HomeActivity$2.onPostExecute(HomeActivity.java:1)
04-25 20:49:46.999: E/AndroidRuntime(7904):     at android.os.AsyncTask.finish(AsyncTask.java:417)
04-25 20:49:46.999: E/AndroidRuntime(7904):     at android.os.AsyncTask.access$300(AsyncTask.java:127)
04-25 20:49:46.999: E/AndroidRuntime(7904):     at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
04-25 20:49:46.999: E/AndroidRuntime(7904):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-25 20:49:46.999: E/AndroidRuntime(7904):     at android.os.Looper.loop(Looper.java:130)
04-25 20:49:46.999: E/AndroidRuntime(7904):     at android.app.ActivityThread.main(ActivityThread.java:3835)
04-25 20:49:46.999: E/AndroidRuntime(7904):     at java.lang.reflect.Method.invokeNative(Native Method)
04-25 20:49:46.999: E/AndroidRuntime(7904):     at java.lang.reflect.Method.invoke(Method.java:507)
04-25 20:49:46.999: E/AndroidRuntime(7904):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
04-25 20:49:46.999: E/AndroidRuntime(7904):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
04-25 20:49:46.999: E/AndroidRuntime(7904):     at dalvik.system.NativeStart.main(Native Method)

I've done class is static because app crash:

> 04-25 20:48:50.757: E/AndroidRuntime(7863): Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.fisherman.activity.HomeActivity$ProgressDialogFragment: make sure class name exists, is public, and has an empty constructor that is public
04-25 20:48:50.757: E/AndroidRuntime(7863):     at android.support.v4.app.Fragment.instantiate(Fragment.java:405)
04-25 20:48:50.757: E/AndroidRuntime(7863):     at android.support.v4.app.FragmentState.instantiate(Fragment.java:97)
04-25 20:48:50.757: E/AndroidRuntime(7863):     at android.support.v4.app.FragmentManagerImpl.restoreAllState(FragmentManager.java:1767)
04-25 20:48:50.757: E/AndroidRuntime(7863):     at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:208)
04-25 20:48:50.757: E/AndroidRuntime(7863):     at com.fisherman.activity.HomeActivity.onCreate(HomeActivity.java:50)
04-25 20:48:50.757: E/AndroidRuntime(7863):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-25 20:48:50.757: E/AndroidRuntime(7863):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
04-25 20:48:50.757: E/AndroidRuntime(7863):     ... 12 more
04-25 20:48:50.757: E/AndroidRuntime(7863): Caused by: java.lang.InstantiationException: com.fisherman.activity.HomeActivity$ProgressDialogFragment
04-25 20:48:50.757: E/AndroidRuntime(7863):     at java.lang.Class.newInstanceImpl(Native Method)
04-25 20:48:50.757: E/AndroidRuntime(7863):     at java.lang.Class.newInstance(Class.java:1409)
04-25 20:48:50.757: E/AndroidRuntime(7863):     at android.support.v4.app.Fragment.instantiate(Fragment.java:394)
Indigene answered 25/4, 2013 at 19:1 Comment(1)
I'm seeing the same thing. Did you ever find a resolution?Shushubert
C
4

Have you dismiss dialog on postexecute? it might create app to crash So if you forgot to dismiss dialog please dismiss it on postexecute.

Cata answered 28/5, 2014 at 7:20 Comment(0)
F
0

HomeActivity$2.onPostExecute(HomeActivity.java:268)

Are you call dialog in async?

Fluffy answered 9/9, 2013 at 12:19 Comment(3)
Yes. I call dialog in AsyncTask.Indigene
if you call in onbackground metot,you dont call view arguments in onbackround.Fluffy
I don't call view on background. I call dialog in onPreExecue and in onPostExecute methods.Indigene

© 2022 - 2024 — McMap. All rights reserved.