当前位置: 代码迷 >> Android >> Android Null Pointer的有关问题
  详细解决方案

Android Null Pointer的有关问题

热度:36   发布时间:2016-05-01 14:53:57.0
Android Null Pointer的问题
Java code
我在主activity里面设置了有三个tab的切换卡,在第三个tab里面是个ListView,单击ListView会弹出时间选择对话框public void onSetWarn(){        LayoutInflater factoryInflater = LayoutInflater.from(MainActivity.this);        final View dialogView = factoryInflater.inflate(R.layout.dialog, null);        AlertDialog dialog = new AlertDialog.Builder(MainActivity.this).setTitle("设置")                .setView(dialogView)                .setPositiveButton("确定", new DialogInterface.OnClickListener() {                                        public void onClick(DialogInterface dialog, int which) {                        Toast.makeText(getApplicationContext(), "设置成功!", Toast.LENGTH_SHORT).show();                    }                })                .setNegativeButton("取消", new DialogInterface.OnClickListener() {                                        public void onClick(DialogInterface dialog, int which) {                                            }                }).create();        /*        timePicker = (TimePicker) this.findViewById(R.id.TimePicker1);        timePicker.setIs24HourView(true);        */        dialog.show();    }

我到底该把timePicker = (TimePicker) this.findViewById(R.id.TimePicker1);
timePicker.setIs24HourView(true);
这段代码放在哪呢? 我试了好几个地方都是NULL pointer错误

------解决方案--------------------
timePicker = (TimePicker) this.findViewById(R.id.TimePicker1);
this换成dialogView,
  相关解决方案