当我单击此警报对话框的肯定按钮时,应用程序崩溃。这段代码有什么问题吗?我感觉复选框分配不正确。
private void showSmimeSettings(){
AlertDialog.Builder smimeBuilder = new AlertDialog.Builder(this);
smimeBuilder.setTitle("S/MIME Settings");
LayoutInflater inflator = getLayoutInflater();
View checkboxLayout = inflator.inflate(R.layout.smime_settings_checkbox, null);
smimeBuilder.setView(checkboxLayout);
final CheckBox signed_checkbox = (CheckBox) findViewById(R.id.signed_checkBox);
final CheckBox encrypted_checkbox = (CheckBox) findViewById(R.id.encrypted_checkBox);
smimeBuilder.setPositiveButton("Save", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
if (signed_checkbox.isChecked()) {
mIsSigned = true;
} else {
mIsSigned = false;
}
if (encrypted_checkbox.isChecked()) {
mIsEncrypted = true;
} else {
mIsEncrypted = false;
}
}
});
AlertDialog smimeDialog = smimeBuilder.create();
smimeDialog.show();
}
日志:
06-14 17:08:59.041: E/com.fm.sg.android.sgApplication(4131): Thread uncaught exception:
06-14 17:08:59.041: E/com.fm.sg.android.sgApplication(4131): java.lang.NullPointerException
06-14 17:08:59.041: E/com.fm.sg.android.sgApplication(4131): at com.android.lexperts.email.activity.MessageCompose$7.onClick(MessageCompose.java:1647)
06-14 17:08:59.041: E/com.fm.sg.android.sgApplication(4131): at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:166)
06-14 17:08:59.041: E/com.fm.sg.android.sgApplication(4131): at android.os.Handler.dispatchMessage(Handler.java:99)
06-14 17:08:59.041: E/com.fm.sg.android.sgApplication(4131): at android.os.Looper.loop(Looper.java:137)
06-14 17:08:59.041: E/com.fm.sg.android.sgApplication(4131): at android.app.ActivityThread.main(ActivityThread.java:5039)
06-14 17:08:59.041: E/com.fm.sg.android.sgApplication(4131): at java.lang.reflect.Method.invokeNative(Native Method)
06-14 17:08:59.041: E/com.fm.sg.android.sgApplication(4131): at java.lang.reflect.Method.invoke(Method.java:511)
06-14 17:08:59.041: E/com.fm.sg.android.sgApplication(4131): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-14 17:08:59.041: E/com.fm.sg.android.sgApplication(4131): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-14 17:08:59.041: E/com.fm.sg.android.sgApplication(4131): at dalvik.system.NativeStart.main(Native Method)
06-14 17:08:59.041: E/ACRA(4131): ACRA caught a NullPointerException exception for com.fm.sg.android. Building report.
06-14 17:09:02.252: E/ACRA(4131): com.fm.sg.android fatal error : null
06-14 17:09:02.252: E/ACRA(4131): java.lang.NullPointerException
06-14 17:09:02.252: E/ACRA(4131): at com.android.lexperts.email.activity.MessageCompose$7.onClick(MessageCompose.java:1647)
06-14 17:09:02.252: E/ACRA(4131): at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:166)
06-14 17:09:02.252: E/ACRA(4131): at android.os.Handler.dispatchMessage(Handler.java:99)
06-14 17:09:02.252: E/ACRA(4131): at android.os.Looper.loop(Looper.java:137)
06-14 17:09:02.252: E/ACRA(4131): at android.app.ActivityThread.main(ActivityThread.java:5039)
06-14 17:09:02.252: E/ACRA(4131): at java.lang.reflect.Method.invokeNative(Native Method)
06-14 17:09:02.252: E/ACRA(4131): at java.lang.reflect.Method.invoke(Method.java:511)
06-14 17:09:02.252: E/ACRA(4131): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-14 17:09:02.252: E/ACRA(4131): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-14 17:09:02.252: E/ACRA(4131): at dalvik.system.NativeStart.main(Native Method)