我有一个自定义对话框。所以单击按钮我正在显示它。现在我在自定义对话框中有一个按钮,我想在单击该按钮时关闭它,但它会引发任何空指针异常。这是我的代码用来显示它:
private void showPreConfirmationDialog() {
final Dialog dialog= new Dialog(context);;
button = (ImageView) findViewById(R.id.bookButton);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
dialog.setContentView(R.layout.pre_confirmation_dailog);
//dialog.setCancelable(false);
dialog.setTitle("OnWard Details...");
dialog.show();
}
});
backPreConfirmation = (ImageView)dialog.findViewById(R.id.backImage);
backPreConfirmation.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
dialog.dismiss();
}
});
}
单击 backPreConfirmation 按钮时,它会抛出我的这个错误:
07-30 09:25:15.830: E/AndroidRuntime(26599): FATAL EXCEPTION: main
07-30 09:25:15.830: E/AndroidRuntime(26599): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.result/com.android.result.Result}: java.lang.NullPointerException
07-30 09:25:15.830: E/AndroidRuntime(26599): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
07-30 09:25:15.830: E/AndroidRuntime(26599): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
07-30 09:25:15.830: E/AndroidRuntime(26599): at android.app.ActivityThread.access$600(ActivityThread.java:141)
07-30 09:25:15.830: E/AndroidRuntime(26599): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
07-30 09:25:15.830: E/AndroidRuntime(26599): at android.os.Handler.dispatchMessage(Handler.java:99)
07-30 09:25:15.830: E/AndroidRuntime(26599): at android.os.Looper.loop(Looper.java:137)
07-30 09:25:15.830: E/AndroidRuntime(26599): at android.app.ActivityThread.main(ActivityThread.java:5041)
07-30 09:25:15.830: E/AndroidRuntime(26599): at java.lang.reflect.Method.invokeNative(Native Method)
07-30 09:25:15.830: E/AndroidRuntime(26599): at java.lang.reflect.Method.invoke(Method.java:511)
07-30 09:25:15.830: E/AndroidRuntime(26599): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-30 09:25:15.830: E/AndroidRuntime(26599): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-30 09:25:15.830: E/AndroidRuntime(26599): at dalvik.system.NativeStart.main(Native Method)
07-30 09:25:15.830: E/AndroidRuntime(26599): Caused by: java.lang.NullPointerException
07-30 09:25:15.830: E/AndroidRuntime(26599): at com.android.result.Result.showPreConfirmationDialog(Result.java:66)
07-30 09:25:15.830: E/AndroidRuntime(26599): at com.android.result.Result.onCreate(Result.java:41)
07-30 09:25:15.830: E/AndroidRuntime(26599): at android.app.Activity.performCreate(Activity.java:5104)
07-30 09:25:15.830: E/AndroidRuntime(26599): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
07-30 09:25:15.830: E/AndroidRuntime(26599): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
07-30 09:25:15.830: E/AndroidRuntime(26599): ... 11 more
我有什么问题请告诉我