title: Android Dialog Button.setonClickListener
body: <p>When I create a dialog and set an onClickListener on a button, the app crashes. The same code works in another Activity, so what's the matter?</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
              WindowManager.LayoutParams.FLAG_FULLSCREEN);
      initNewUserDialog();
      initNewLocationDialog();
  </code></pre>
  
  <p>...</p>
  
  <pre><code>private void initNewLocationDialog() {
      new_location_Dialog = new Dialog(this, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
      setContentView(R.layout.new_location);
      new_location_Button = (Button)new_location_Dialog.findViewById(R.id.newlocation_ok);
      //Crash here
      new_location_Button.setOnClickListener(new View.OnClickListener() { 
          @Override
          public void onClick(View v) {
              new_location_Dialog.dismiss();
          }
      });
      new_location_editText = (EditText)new_location_Dialog.findViewById(R.id.newlocation_edittext);
      new_location_Dialog.hide();
  }
  </code></pre>