title: android setOnClickListener gives null pointer exception?
body: <p>I have written code for <code>onClick</code> method for Custom Dialog top of the another view. It gives me <code>nullpointer exception</code>. I've also tried using Layout inflater. It gives me error on <code>ok.setOnclickListener</code>. What's wrong in my code?</p>
  
  <pre><code> ImageButton search =(ImageButton) findViewById(R.id.search);
              search.setOnClickListener(new OnClickListener() {
  
                  @Override
                  public void onClick(View v) {
  
                      Dialog searchDialog = new Dialog(Page.this);
  
                      /*LayoutInflater inflater = (LayoutInflater) getApplicationContext()
                  .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  
  
                       View layout = inflater.inflate(R.layout.search, null);
                       searchDialog.addContentView(layout, new LayoutParams(
                                  LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
                       searchDialog.setContentView(layout);*/
  
                      searchDialog.setContentView(R.layout.search);
                      searchDialog.setTitle("Search Dialog");
                      searchDialog.setCancelable(true);
  
                      Button ok = (Button)findViewById(R.id.OkButton);
                      ok.setOnClickListener(new OnClickListener() {
  
                          @Override
                          public void onClick(View v) {
                              String searchString = null;
                              EditText searchText = (EditText)findViewById(R.id.searchText);
                              if(searchText.getText()!=null){
                                  searchString = searchText.getText().toString();
                              }
                              Log.i("TAG","Search word :"+searchString);
  
                          }
                      });
  
                      searchDialog.show();
  
  
  
                  }
  
  
              });
  </code></pre>