findViewById returns null
<p>I have code:</p>

<pre><code>public class HelloWorld extends Activity {

private Button buttonOk;
private Button buttonCancel;

private OnClickListener buttonOkListener = new OnClickListener() {
    public void onClick(View v){
        EditText editText = (EditText)findViewById(R.id.input);

        CharSequence textFromInput = (CharSequence) editText.getText();
        Context context = getApplicationContext();
        int duration = Toast.LENGTH_SHORT;

        Toast toast = Toast.makeText(context,textFromInput,duration);
        toast.show();
    }
};

private OnClickListener buttonCancelListener = new OnClickListener() {
    public void onClick(View v){
        EditText editText = (EditText)findViewById(R.id.input);

        CharSequence textFromInput = (CharSequence) editText.getText();
        Context context = getApplicationContext();
        int duration = Toast.LENGTH_SHORT;

        Toast toast = Toast.makeText(context,textFromInput,duration);
        toast.show();
    }
};

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    // ToDo add your GUI initialization code here

    setContentView(R.layout.main);

    buttonOk = (Button)findViewById(R.id.buttonOk);
    buttonCancel = (Button)findViewById(R.id.buttonCancel);

    buttonOk.setOnClickListener(buttonOkListener);
    buttonCancel.setOnClickListener(buttonCancelListener);
}
}
</code></pre>

<p>and the layout file:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;RelativeLayout 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="Wpisz swoje imię:"/&gt;
&lt;EditText
    android:id="@+id/input"
    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/buttonOk"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/input"
    android:layout_alignParentRight="true"
    android:layout_marginLeft="10dip"
    android:text="OK" /&gt;
&lt;Button
    android:id="@+id/buttonCancel"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toLeftOf="@id/buttonOk"
    android:layout_alignTop="@id/buttonOk"
    android:text="Anuluj" /&gt;
&lt;/RelativeLayout&gt;
</code></pre>

<p>Line with buttonCancel.setOnClickListener(buttonCancelListener); throws an Exception because buttonCancel is null. What i am doing wrong?</p>
