Z_dong_dong
Z_dong_dong
采纳率10%
2015-06-10 03:16 阅读 1.8k

oncreateDialog时报了空指针异常,求大神指导一下,我也找不到原因所在

报这个异常,我也搜了相关资料,很多人代码里最后default也返回null,为什么我报错呀?求大神知道,代码在最下面
java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2378)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2430)
at android.app.ActivityThread.access$600(ActivityThread.java:166)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1374)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5400)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:853)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.netschool.mock.MockListActivity.onCreateDialog(Unknown Source)
at android.app.Activity.onCreateDialog(Activity.java:3089)
at android.app.Activity.createDialog(Activity.java:1072)
at android.app.Activity.restoreManagedDialogs(Activity.java:1061)
at android.app.Activity.performRestoreInstanceState(Activity.java:1007)
at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1202)
at com.lbe.security.service.core.client.internal.InstrumentationDelegate.callActivityOnRestoreInstanceState(InstrumentationDelegate.java:130)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2356)
... 11 more

代码
 @Override
    protected Dialog onCreateDialog(int id) {
        m_pickerDialog = null;
        switch (id) {
        case 0:

            m_pickerDialog = new DatePickerDialog_WithoutDate(this, new DatePickerDialog.OnDateSetListener() {
                @Override
                public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                    Message msg = Message.obtain();
                    msg.arg1 = year;
                    msg.arg2 = monthOfYear + 1;
                    msg.what = MsgWhat.MSG_ANSW_RECO_ACTI_15;
                    m_handlerPostExecute.sendMessage(msg);

                }
            }, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));
            break;
        }
        m_pickerDialog.setTitle(calendar.get(Calendar.YEAR) + " 年 " + (calendar.get(Calendar.MONTH) + 1)
                + " 月");
        return m_pickerDialog;
    }
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

4条回答 默认 最新

  • danielinbiti danielinbiti 2015-06-10 03:26
     如果传入的id不等于0,m_pickerDialog.setTitle就报空指针了。
    
    点赞 评论 复制链接分享
  • bdmh bdmh 2015-06-10 03:28

    如果id不等于0,就是跳过来case 0,那样m_pickerDialog就没有被初始化,你后面访问就会报空指针

    点赞 评论 复制链接分享
  • u011240877 拭心 2015-06-11 10:04

    我觉得switch里应该设置个default

    点赞 评论 复制链接分享
  • vdsvfdsbfdgf 大树底下的苹果 2015-06-26 08:56

    你在switch case外面也加一个new试试看啊

    点赞 评论 复制链接分享

相关推荐