Timmy-zzh / TDialog

DialogFragment封装,高效实现各种弹窗效果
482 stars 93 forks source link

使用dialog时一直报这个异常,排查不出原因 #35

Open 258188170 opened 5 years ago

258188170 commented 5 years ago

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.yunzong.cloudbox/com.xiyun.cloudbox.mvp.ui.activity.ShiftDetailActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View com.xiyun.cloudbox.app.weight.dialog.base.TController.o()' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3947) at android.app.ActivityThread.access$900(ActivityThread.java:151) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1309) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5254) 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:902) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:697) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View com.xiyun.cloudbox.app.weight.dialog.base.TController.o()' on a null object reference at com.xiyun.cloudbox.app.weight.dialog.TDialog.b(TDialog.java:78) at com.xiyun.cloudbox.app.weight.dialog.base.BaseDialogFragment.onCreateView(BaseDialogFragment.java:80) at android.support.v4.app.Fragment.performCreateView(Fragment.java:2439) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1460) at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852) at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3269) at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3229) at android.support.v4.app.FragmentController.dispatchActivityCreated(FragmentController.java:201) at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:620) at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:178) at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1236) at android.app.Activity.performStart(Activity.java:6049) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2288) ... 11 more java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View com.xiyun.cloudbox.app.weight.dialog.base.TController.o()' on a null object reference at com.xiyun.cloudbox.app.weight.dialog.TDialog.b(TDialog.java:78) at com.xiyun.cloudbox.app.weight.dialog.base.BaseDialogFragment.onCreateView(BaseDialogFragment.java:80) at android.support.v4.app.Fragment.performCreateView(Fragment.java:2439) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1460) at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852) at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3269) at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3229) at android.support.v4.app.FragmentController.dispatchActivityCreated(FragmentController.java:201) at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:620) at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:178) at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1236) at android.app.Activity.performStart(Activity.java:6049) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2288) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3947) at android.app.ActivityThread.access$900(ActivityThread.java:151) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1309) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5254) 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:902) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:697)

Timmy-zzh commented 5 years ago

你好,看一下你的调用方法写在哪里

258188170 commented 5 years ago

调用方法比较多但是每次都new了的 tDialog = new TDialog.Builder(getSupportFragmentManager()) .setLayoutRes(R.layout.dialog_version_upgrde) .setWidth(Constants.DIALOG_WIDTH) .setCancelableOutside(false) .setOnBindViewListener((viewHolder) -> { viewHolder.setText(R.id.tv_content, msg); viewHolder.setText(R.id.tv_cancel, getString(R.string.txt_retry)); TextView confirm = viewHolder.getView(R.id.tv_confirm); if (list != null && list.size() > 0) confirm.setText(getString(R.string.txt_use_em)); else confirm.setText(getString(R.string.model_setting));

            })
            .addOnClickListener(R.id.tv_cancel, R.id.tv_confirm)
            .setOnViewClickListener((viewHolder, view, tDialog) -> {
                switch (view.getId()) {
                    case R.id.tv_confirm:
                        tDialog.dismissAllowingStateLoss();

                        if (list != null && list.size() > 0) {
                            //使用应急码
                            mPresenter.clickedEmergency(list);
                        } else {
                            // 跳转到设置界面
                            startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
                        }
                        break;
                    case R.id.tv_cancel:
                        mPresenter.checkNetworkInfo();
                        tDialog.dismissAllowingStateLoss();
                        break;
                }
            })
            .setOnKeyListener((anInterface, i, keyEvent) -> {
                if (i == KeyEvent.KEYCODE_BACK) {
                    finish();
                    return true;
                }
                return false;
            })
            .create()
            .show();
258188170 commented 5 years ago

这个异常我没复现,但是友盟统计上一直上报

258188170 commented 5 years ago

image image

258188170 commented 5 years ago

image 不同界面都报这个空指针异常

Timmy-zzh commented 5 years ago

你好,我需要知道你在哪里 new TDialog.Builder(),因为我要分析虚拟机栈信息,根据你提供的资料在调用performLaunchActivity()时触发异常,我想知道你调用new TDialog.Builder()的入口函数在哪里?可以的话加我微信(Timmy_zzh)