title: ToggleButton not working
body: <p>I'm new to android. 
  I tried to create a simple toggle button and catch it's state change. But it crashes when I run it on my device. </p>
  
  <p>Here is the MainActivity.java code:</p>
  
  <pre><code>package com.example.addimagebutton;
  
  import android.os.Bundle;
  import android.app.Activity;
  import android.widget.CompoundButton;
  import android.widget.CompoundButton.OnCheckedChangeListener;
  import android.widget.Toast;
  import android.widget.ToggleButton;
  
  public class MainActivity extends Activity {
  
      private ToggleButton tbSwitch;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          tbSwitch = (ToggleButton) findViewById(R.id.swButton);
          tbSwitch.setOnCheckedChangeListener(toggleListener);
      }
  
      OnCheckedChangeListener toggleListener = new OnCheckedChangeListener() {
  
          @Override
          public void onCheckedChanged(CompoundButton buttonView,
                  boolean isChecked) {
              // TODO Auto-generated method stub
              if (isChecked) {
                  Toast.makeText(getApplicationContext(), "On",
                          Toast.LENGTH_SHORT).show();
              } else {
                  Toast.makeText(getApplicationContext(), "Off",
                          Toast.LENGTH_SHORT).show();
              }
          }
      };
  }
  </code></pre>
  
  <p>Here is activity_main.xml code:</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical" &gt;
  
      &lt;Switch
          android:id="@+id/swButton"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:text="Switch"
          android:textOff="Off"
          android:textOn="On" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>I tried to run this code without the listener objects.(commenting those) But it gave me the same result.</p>