我有脚本如果切换对话框onchecked将显示自定义对话框。如果buttonUpdate删除di customdialog show但是如果我使用buttonUpdate它将强制关闭。请帮忙
ToggleButton toogleStatus = (ToggleButton) findViewById(R.id.toggleStatus);
// toogleStatus.setChecked(true);
toogleStatus.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
// TODO Auto-generated method stub
Dialog dialog = new Dialog(DashboardActivity.this);
dialog.setContentView(R.layout.dialog_layout);
dialog.setTitle("Buat Status");
dialog.setCancelable(true);
//there are a lot of settings, for dialog, check them all out!
buttonUpdate = (Button)findViewById(R.id.buttonUpdate);
buttonUpdate.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
//now that the dialog is set up, it's time to show it
dialog.show();
}
});
错误消息
06-17 19:35:15.059: E/AndroidRuntime(3790): FATAL EXCEPTION: main
06-17 19:35:15.059: E/AndroidRuntime(3790): java.lang.NullPointerException
06-17 19:35:15.059: E/AndroidRuntime(3790): at net.drieanto.lagidimana.DashboardActivity$2.onCheckedChanged(DashboardActivity.java:129)
06-17 19:35:15.059: E/AndroidRuntime(3790): at android.widget.CompoundButton.setChecked(CompoundButton.java:125)
06-17 19:35:15.059: E/AndroidRuntime(3790): at android.widget.ToggleButton.setChecked(ToggleButton.java:72)
06-17 19:35:15.059: E/AndroidRuntime(3790): at android.widget.CompoundButton.toggle(CompoundButton.java:87)
06-17 19:35:15.059: E/AndroidRuntime(3790): at android.widget.CompoundButton.performClick(CompoundButton.java:99)
06-17 19:35:15.059: E/AndroidRuntime(3790): at android.view.View$PerformClick.run(View.java:14105)
06-17 19:35:15.059: E/AndroidRuntime(3790): at android.os.Handler.handleCallback(Handler.java:605)
06-17 19:35:15.059: E/AndroidRuntime(3790): at android.os.Handler.dispatchMessage(Handler.java:92)
06-17 19:35:15.059: E/AndroidRuntime(3790): at android.os.Looper.loop(Looper.java:137)
06-17 19:35:15.059: E/AndroidRuntime(3790): at android.app.ActivityThread.main(ActivityThread.java:4424)
06-17 19:35:15.059: E/AndroidRuntime(3790): at java.lang.reflect.Method.invokeNative(Native Method)
06-17 19:35:15.059: E/AndroidRuntime(3790): at java.lang.reflect.Method.invoke(Method.java:511)
06-17 19:35:15.059: E/AndroidRuntime(3790): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
06-17 19:35:15.059: E/AndroidRuntime(3790): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
06-17 19:35:15.059: E/AndroidRuntime(3790): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:0)
我相信这会解决你的问题
buttonUpdate = (Button) dialog.findViewById(R.id.buttonUpdate);
假设dialog_layout包含Button
buttonUpdate