Android:DialogFragment.dismissInternal 处 DialogFragment.dismissAllow 处的 NullPointerException

Posted

技术标签:

【中文标题】Android:DialogFragment.dismissInternal 处 DialogFragment.dismissAllow 处的 NullPointerException【英文标题】:Android: NullPointerException at DialogFragment.dismissInternal at DialogFragment.dismissAllow 【发布时间】:2013-04-19 19:36:08 【问题描述】:

显示 ProgressDialog 时应用程序崩溃。我正在使用滑出式键盘在手机上进行测试。当显示对话框时,我滑动键盘和应用程序崩溃。

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());
        
    


崩溃日志:

> 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)

我的课程是静态的,因为应用程序崩溃:

> 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)

【问题讨论】:

我也看到了同样的情况。你有没有找到解决办法? 【参考方案1】:

您是否在执行后关闭对话框?它可能会导致应用程序崩溃 因此,如果您忘记关闭对话框,请在执行后关闭它。

【讨论】:

【参考方案2】:

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

你是在异步调用对话框吗?

【讨论】:

是的。我在 AsyncTask 中调用对话框。 如果你在 onbackground metot 中调用,你不会在 onbackround 中调用视图参数。 我不调用背景视图。我在 onPreExecueonPostExecute 方法中调用对话框。

以上是关于Android:DialogFragment.dismissInternal 处 DialogFragment.dismissAllow 处的 NullPointerException的主要内容,如果未能解决你的问题,请参考以下文章

Android 逆向Android 权限 ( Android 逆向中使用的 android.permission 权限 | Android 系统中的 Linux 用户权限 )

android 21 是啥版本

Android逆向-Android基础逆向(2-2)

【Android笔记】android Toast

图解Android - Android核心机制

Android游戏开发大全的目录