title: Android application crashes at launch whenever I attach an onclicklistener to a button
body: <p>Hey guys. I'm writing an app to retrieve last fm albums at the moment and whenever I attach an onclicklistener to my button, created in search_layout.xml, it crashes at launch. If I comment out the listener, it doesn't crash. Heres the code:</p>
  
  <pre><code>public class SearchActivity extends Activity{
  
  //data members
  private EditText movieName;
  private Button okayBut;
  private Button cancelBut;
  private URL url;
  private InputStream in;
  private TextView tv;
  private LastFMAlbumHandler lfmah;
  private Vector&lt;String&gt; parsedVector;
  private String picUrlString;
  private URL picUrl;
  private SearchActivity search;
  private RelativeLayout layout;
  
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      //initalize variables below
      movieName = (EditText) findViewById(R.id.entry);        
      okayBut = (Button) findViewById(R.id.ok);
      cancelBut = (Button) findViewById(R.id.cancel);
      layout = (RelativeLayout) findViewById(R.id.layout);
      search = this;
  
  
  
   this.okayBut.setOnClickListener(new Button.OnClickListener() {
              @Override
              public void onClick(View v) {
  //      
              try{
  //                      url = new URL("http://ws.audioscrobbler.com/2.0/?method=artist.gettopalbums&amp;artist=cher&amp;api_key=b25b959554ed76058ac220b7b2e0a026");
  //                      HttpURLConnection conn = (HttpURLConnection) url.openConnection();
  //                      in = conn.getInputStream(); //now  global variable, was bufferedInputStream
  //                      try{
  //                          lfmah = new LastFMAlbumHandler(tv);
  //                          parseToHandler(in, lfmah);
  //                          parsedVector = lfmah.getResults();
  //                          for(int i = 0; i &lt; parsedVector.size(); i++)
  //                          {
  //                              picUrlString = parsedVector.get(i);
  //                              picUrl = new URL(picUrlString);
  //                              imgGet imageGet = new imgGet(layout, picUrl, search);
  //                              imageGet.run();
  //                          }
  //                      }
  //                      catch (Exception e){
  //                          //fresh.append("couldn't parse");
  //                      }
  //                      finally{
  //                          in.close();
  //                      }
  //                  }catch(Exception e){
  //                      tv.append("could not connect");
  //                  } 
              }
       });    
      setContentView(R.layout.search_layout);
  }
  
  //ParseToHandler method
  private void parseToHandler(InputStream in, CheapHandler handler) throws IOException, ParserConfigurationException, SAXException
  {
      try{
          SAXParserFactory spf = SAXParserFactory.newInstance();
          SAXParser parser = spf.newSAXParser();
          parser.parse(in, handler);
      }
      catch (IOException e)
      {
          tv.append("first");
      }
      catch(ParserConfigurationException e)
      {
          tv.append("second");
      }
      catch (SAXException e)
      {
          tv.append("third");
      }
      catch (Exception e)
      {
          tv.append("unknown");
      }
  }
  
  }
  </code></pre>
  
  <p>and here is the XML code:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout android:id="@+id/layout"  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent" android:layout_height="fill_parent"&gt;
  
  &lt;TextView android:id="@+id/label" android:layout_width="fill_parent"
      android:layout_height="wrap_content" android:text="Enter movie name below:" /&gt;
  
  &lt;EditText android:id="@+id/entry" android:layout_width="fill_parent"
      android:layout_height="wrap_content" android:background="@android:drawable/editbox_background"
      android:layout_below="@id/label" /&gt;
  
  &lt;Button android:id="@+id/ok" android:layout_width="wrap_content"
      android:layout_height="wrap_content" android:layout_below="@id/entry"
      android:layout_alignParentRight="true" android:layout_marginLeft="10dip"
      android:text="OK" /&gt;
  
  &lt;Button android:id="@+id/cancel" android:layout_width="wrap_content"
      android:layout_height="wrap_content" android:layout_toLeftOf="@id/ok"
      android:layout_alignTop="@id/ok" android:text="Cancel" /&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>I would really appreciate any help. Thanks</p>