title: Dismiss A Custom Dialog on Click of Button in Android
body: <p>I have a custom dialog .So a button click i am showing it .Now i have a button in the custom dialog i want to close it on click of that button but it is throwing any null pointer exception.Here is my code that i am using to show it:</p>
  
  <pre><code>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();
  
          }
      });
  }
  </code></pre>
  
  <p>On click of backPreConfirmation button it is throwing my this error :</p>
  
  <pre><code>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
  </code></pre>
  
  <p>What i have wrong please let me know</p>