title: Why does onClickListener not work outside of onCreate method?
body: <p>When I try to use the <code>onClickListener</code> method for a button, variable outside of any <code>onCreate or onPause or onAnything</code> method, it does not work. I also cannot even set the value of a button variable outside of an "onAnything" method. Help would be great. </p>
  
  <p>Thanks!</p>
  
  <pre><code>public class StartingPoint extends Activity {
  /** Called when the activity is first created. */
  
  int counter;
  Button add= (Button) findViewById(R.id.bAdd);
  Button sub= (Button) findViewById(R.id.bSub);
  TextView display= (TextView) findViewById(R.id.tvDisplay);
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      setContentView(R.layout.main);
      Log.i("phase", "on create");
      counter=0;       
  
      add.setOnClickListener(new View.OnClickListener() {
  
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
              counter++;
              display.setText(""+counter);
              display.setTextSize(counter);
              Log.i("phase", "add");
          }
      });
      sub.setOnClickListener(new View.OnClickListener() {
  
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
              counter--;
              display.setText(""+counter);
              display.setTextSize(counter);
              display.setTextColor(Color.GREEN);
              Log.i("phase", "sub");
          }
      });
  
  }
  
  @Override
  protected void onStart() {
      // TODO Auto-generated method stub
      super.onStart();
      Log.i("phase", "on start");
      SharedPreferences prefs = getPreferences(0); 
      int getfromfile = prefs.getInt("counter_store", 1);
      counter=getfromfile;
      display.setText(""+getfromfile);
      display.setTextSize(getfromfile);
  }
  
  @Override
  protected void onStop() {
      // TODO Auto-generated method stub
      super.onStop();
      Log.i("phase", "on stop");
       SharedPreferences.Editor editor = getPreferences(0).edit();
       editor.putInt("counter_store", counter);
       editor.commit();
  }
  
  @Override
  protected void onDestroy() {
      // TODO Auto-generated method stub
      super.onDestroy();
      counter=0;
      Log.i("phase", "on destroy");
  
    }
  
  }
  </code></pre>