Crashing when onClickListener is added
<p>Probably a fairly simple question but I can't seem to make sense of why any onClickListeners I'm adding. (I also seem to get a similar crash when adding a text changed listener to an EditText box, which makes me think I'm consistently setting something up wrong?)</p>

<p>I followed the basic Android Developers stuff which creates an onClickListener as follows...</p>

<pre><code>        mPickDate.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            showDialog(DATE_DIALOG_ID);
        }
    });
</code></pre>

<p>However, I was wanting to create the Listener then have an onCreate method to execute the code.</p>

<p>Here is my current setup which is crashing as soon as I run it</p>

<pre><code>package com.chris.formStuff;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class FormStuffActivity extends Activity implements OnClickListener {

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    // Create the view
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Load all views.
    //EditText edtText1;
    Button btnChange1;

    // And find all views in the relevant layout file
    //edtText1=(EditText) findViewById(R.layout.main);
    btnChange1 = (Button) this.findViewById(R.layout.main);

    btnChange1.setOnClickListener((OnClickListener) this);
}
@Override
public void onClick(View v)
{
    Context context = getApplicationContext();
    CharSequence text = "Hello toast!";
    int duration = Toast.LENGTH_SHORT;

    Toast toast = Toast.makeText(context, text, duration);
    toast.show();
}
}
</code></pre>

<p>And the logcat output...</p>

<pre>
07-25 13:19:10.593: ERROR/AndroidRuntime(22861): FATAL EXCEPTION: main
07-25 13:19:10.593: ERROR/AndroidRuntime(22861): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.chris.formStuff/com.chris.formStuff.FormStuffActivity}: java.lang.ClassCastException: com.chris.formStuff.FormStuffActivity
07-25 13:19:10.593: ERROR/AndroidRuntime(22861):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2787)
07-25 13:19:10.593: ERROR/AndroidRuntime(22861):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2803)
07-25 13:19:10.593: ERROR/AndroidRuntime(22861):     at android.app.ActivityThread.access$2300(ActivityThread.java:135)
07-25 13:19:10.593: ERROR/AndroidRuntime(22861):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2136)
07-25 13:19:10.593: ERROR/AndroidRuntime(22861):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-25 13:19:10.593: ERROR/AndroidRuntime(22861):     at android.os.Looper.loop(Looper.java:144)
07-25 13:19:10.593: ERROR/AndroidRuntime(22861):     at android.app.ActivityThread.main(ActivityThread.java:4937)
07-25 13:19:10.593: ERROR/AndroidRuntime(22861):     at java.lang.reflect.Method.invokeNative(Native Method)
07-25 13:19:10.593: ERROR/AndroidRuntime(22861):     at java.lang.reflect.Method.invoke(Method.java:521)
07-25 13:19:10.593: ERROR/AndroidRuntime(22861):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-25 13:19:10.593: ERROR/AndroidRuntime(22861):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-25 13:19:10.593: ERROR/AndroidRuntime(22861):     at dalvik.system.NativeStart.main(Native Method)
07-25 13:19:10.593: ERROR/AndroidRuntime(22861): Caused by: java.lang.ClassCastException: com.chris.formStuff.FormStuffActivity
07-25 13:19:10.593: ERROR/AndroidRuntime(22861):     at com.chris.formStuff.FormStuffActivity.onCreate(FormStuffActivity.java:25)
07-25 13:19:10.593: ERROR/AndroidRuntime(22861):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1069)
07-25 13:19:10.593: ERROR/AndroidRuntime(22861):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2751)
07-25 13:19:10.593: ERROR/AndroidRuntime(22861):     ... 11 more
</pre>
