DialogFragment : NullPointerException(支持库) [英] DialogFragment : NullPointerException (support library)

查看:22
本文介绍了DialogFragment : NullPointerException(支持库)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用出色的 ACRA 库来接收来自我的应用的错误报告.

I'm using the excellent ACRA library to receive error reports from my apps.

我从客户那里收到了很多关于 DialogFragment 中的 NPE 的报告,但我无法重现它:

I'm receiving a lot of reports from customers concerning an NPE in DialogFragment, but Im unable to reproduce it :

java.lang.NullPointerException
at android.support.v4.app.DialogFragment.onActivityCreated(SourceFile:366)
at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:892)
at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1083)
at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1065)
at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(SourceFile:1844)
at android.support.v4.app.FragmentActivity.onStart(SourceFile:519)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1133)
at android.app.Activity.performStart(Activity.java:4475)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1929)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
at android.app.ActivityThread.access$600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
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:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)

NPE 发生在支持库(@line 366)中:

The NPE happens inside the support library (@line 366):

353    @Override
354    public void onActivityCreated(Bundle savedInstanceState) {
           (...)
361        View view = getView();
362        if (view != null) {
363            if (view.getParent() != null) {
364                throw new IllegalStateException("DialogFragment can not be attached             to a container view");
365            }
366            mDialog.setContentView(view);
367        }

我无法在我的任何设备(从 2.2 到 4.1.1)上重现该问题.由于没有引用我的任何代码,这是一个库错误吗?

Im unable to reproduce the problem on any of my device (from 2.2 to 4.1.1). Since there's no reference to any of my code, is it a library bug?

推荐答案

我不得不在项目中调试相同的问题.

I have had to debug the same issue in a project.

通常使用对话框片段如下

Typically Dialog fragment is used as below

@Override
public Dialog onCreateDialog (Bundle savedInstanceState)
{
  //Create custom dialog
  return dialog;
}

尝试将其更新为以下内容

Try updating it to the following

@Override
public Dialog onCreateDialog (Bundle savedInstanceState)
{
  //Create custom dialog
  if (dialog == null)
    super.setShowsDialog (false);

  return dialog;
}

这将阻止 DialogFragment.onAtivityCreated() 在空成员变量 mDialog 上执行方法.

This will prevent DialogFragment.onAtivityCreated() from executing methods on the null member variable mDialog.

这篇关于DialogFragment : NullPointerException(支持库)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆