title: Android: Animation in ImageView wont run
body: <p>when i try to go to the activity where the animation is, it always crash. and my log cat is here and my other files are here.</p>
  
  <p>Im trying to creating an animation through DrawableAnimation here but i don't know why there is an error when i set the backround resource</p>
  
  <h2>LogCat</h2>
  
  <pre><code>02-03 18:52:30.323 4831-4831/com.secsys.gagacamaso.gagacamaso E/AndroidRuntime: FATAL EXCEPTION: main
                                                                              Process: com.secsys.gagacamaso.gagacamaso, PID: 4831
                                                                              java.lang.RuntimeException: Unable to start activity ComponentInfo{com.secsys.gagacamaso.gagacamaso/com.secsys.gagacamaso.gagacamaso.Menu}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setBackgroundResource(int)' on a null object reference
                                                                                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
                                                                                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
                                                                                  at android.app.ActivityThread.-wrap11(ActivityThread.java)
                                                                                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
                                                                                  at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                  at android.os.Looper.loop(Looper.java:148)
                                                                                  at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                                  at java.lang.reflect.Method.invoke(Native Method)
                                                                                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                                               Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setBackgroundResource(int)' on a null object reference
                                                                                  at com.secsys.gagacamaso.gagacamaso.Menu.onCreate(Menu.java:31)
                                                                                  at android.app.Activity.performCreate(Activity.java:6237)
                                                                                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
                                                                                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
                                                                                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                                                                                  at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                                                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                                                                                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                  at android.os.Looper.loop(Looper.java:148) 
                                                                                  at android.app.ActivityThread.main(ActivityThread.java:5417) 
  </code></pre>
  
  <h2>Menu.java</h2>
  
  <pre><code>public class Menu extends Activity {
  
  ImageButton enable;
  ImageView rm1;
  
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.menu);
      setViews();
      enable = (ImageButton)findViewById(R.id.enable);
      lock();
  
  
      rm1.setBackgroundResource(R.drawable.rm_animation);
  
  }
  
  public void setViews(){
      ImageView rm1 = (ImageView)findViewById(R.id.rm1);
  }
  
  private void lock(){
      enable.setTag(1);
      enable.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              final int state =(Integer) v.getTag();
              if(state == 1) {
                  Toast.makeText(Menu.this, "ENABLED!", Toast.LENGTH_SHORT).show();
                  enable.setBackgroundResource(R.drawable.disable);
                  AnimationDrawable rmanim = (AnimationDrawable) rm1.getBackground();
                  rmanim.start();
                  v.setTag(0);
              } else {
                  Toast.makeText(Menu.this, "DISABLED!", Toast.LENGTH_SHORT).show();
                  enable.setBackgroundResource(R.drawable.enable);
                  v.setTag(1); //pause
              }
          }
      });
  }
  </code></pre>
  
  <h2>rm_animation.xml (inside drawable folder)</h2>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;animation-list xmlns:android="http://schemas.android.com/apk/res/android"
      android:oneshot="true"&gt;
      &lt;item android:drawable="@drawable/rm1" android:duration="150"/&gt;
      &lt;item android:drawable="@drawable/rm1glow1" android:duration="150"/&gt;
      &lt;item android:drawable="@drawable/rm1glow2" android:duration="150"/&gt;
      &lt;item android:drawable="@drawable/rm1glow3" android:duration="150"/&gt;
  
  &lt;/animation-list&gt;
  </code></pre>
  
  <h2>menu.xml</h2>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical" android:layout_width="match_parent"
  android:layout_height="match_parent"&gt;
  
  
  &lt;GridLayout
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_gravity="center_horizontal"
      android:layout_marginTop="100dp"
      android:layout_centerHorizontal="true"
      android:id="@+id/gridLayout2"&gt;
  
      &lt;ImageView
          android:layout_width="100dp"
          android:layout_height="100dp"
          android:id="@+id/rm1"
          android:layout_row="0"
          android:layout_column="0"/&gt;
  
      &lt;ImageView
          android:layout_width="100dp"
          android:layout_height="100dp"
          android:id="@+id/rm4"
          android:layout_row="0"
          android:layout_column="2"
          android:background="@drawable/rm1"/&gt;
  
      &lt;ImageView
          android:layout_width="100dp"
          android:layout_height="100dp"
          android:id="@+id/rm2"
          android:layout_row="1"
          android:layout_column="0"
          android:background="@drawable/rm1"/&gt;
  
      &lt;ImageView
          android:layout_width="100dp"
          android:layout_height="100dp"
          android:id="@+id/rm5"
          android:layout_row="1"
          android:layout_column="2"
          android:background="@drawable/rm1"/&gt;
  
      &lt;ImageView
          android:layout_width="100dp"
          android:layout_height="100dp"
          android:id="@+id/rm3"
          android:layout_row="2"
          android:layout_column="0"
          android:background="@drawable/rm1"/&gt;
      &lt;ImageView
          android:layout_width="100dp"
          android:layout_height="100dp"
          android:id="@+id/lrm1"
          android:layout_row="0"
          android:layout_column="1"
          android:layout_gravity="fill_vertical"
          android:layout_rowSpan="3"
          android:background="@drawable/rm2"/&gt;
  
      &lt;ImageView
          android:layout_width="100dp"
          android:layout_height="100dp"
          android:id="@+id/lrm2"
          android:layout_row="2"
          android:layout_column="2"
          android:background="@drawable/rm2a"/&gt;
  
  &lt;/GridLayout&gt;
  
  &lt;ImageButton
      android:layout_width="200dp"
      android:layout_height="50dp"
      android:id="@+id/enable"
      android:layout_below="@+id/gridLayout2"
      android:layout_centerHorizontal="true"
      android:background="@drawable/enable"/&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>