title: Android: Insert animation to dialog
body: <p>I want to repose to onitemclick using a dialog. and also in the dialog i want to embed small animation. I have already done that but it is showing my runtime error.</p>
  
  <pre><code>public class Basic extends Activity {
      final Context context = this;
      EditText inputSearch;
      private ListView lv;
      ArrayAdapter&lt;String&gt; adapter;
      AnimationDrawable frameAnimation;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_word);
          // storing string resources into Array
          String[] adobe_products = getResources().getStringArray(R.array.basic_words);
  
          adapter = new ArrayAdapter&lt;String&gt;(this, R.layout.list_item, R.id.label, adobe_products);
          Arrays.sort(adobe_products, String.CASE_INSENSITIVE_ORDER);
          // ListView lv = getListView();
          lv = (ListView) findViewById(R.id.list);
          inputSearch = (EditText) findViewById(R.id.inputSearch);
          lv.setAdapter(adapter);
  
          inputSearch.addTextChangedListener(new TextWatcher() {
  
              @Override
              public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
                  // When user changed the Text
                  Basic.this.adapter.getFilter().filter(cs);
              }
  
              @Override
              public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
                  // TODO Auto-generated method stub
  
              }
  
              @Override
              public void afterTextChanged(Editable arg0) {
                  // TODO Auto-generated method stub
              }
          });
          // listening to single list item on click
          lv.setOnItemClickListener(new OnItemClickListener() {
              public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
                  String itemValue = (String) parent.getItemAtPosition(position);
                  final Dialog dialog = new Dialog(context);
  
                  switch (position) {
  
                      case 10:
                          dialog.setContentView(R.layout.anim);
                          ImageView image1 = (ImageView) dialog.findViewById(R.id.anim_image);
                          Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
                          dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
                          dialog.setTitle(itemValue);
                          image1.setImageResource(R.drawable.spin_animation);
                          frameAnimation = (AnimationDrawable) image1.getBackground();
  
                          // Start the animation (looped playback by default).
                          frameAnimation.start();
                          dialogButton.setOnClickListener(new OnClickListener() {
                              @Override
                              public void onClick(View v) {
                                  dialog.dismiss();
                              }
                          });
                          dialog.show();
  
                  }
  
              }
          });
      }
  }
  </code></pre>
  
  <p>the log file is looks like this:</p>
  
  <pre><code>11-26 06:53:18.983: E/AndroidRuntime(1734): FATAL EXCEPTION: main
  11-26 06:53:18.983: E/AndroidRuntime(1734): java.lang.NullPointerException
  11-26 06:53:18.983: E/AndroidRuntime(1734):     at org.example.ihear.Basic$2.onItemClick(Basic.java:94)
  11-26 06:53:18.983: E/AndroidRuntime(1734):     at android.widget.AdapterView.performItemClick(AdapterView.java:298)
  11-26 06:53:18.983: E/AndroidRuntime(1734):     at android.widget.AbsListView.performItemClick(AbsListView.java:1100)
  11-26 06:53:18.983: E/AndroidRuntime(1734):     at android.widget.AbsListView$PerformClick.run(AbsListView.java:2788)
  11-26 06:53:18.983: E/AndroidRuntime(1734):     at android.widget.AbsListView$1.run(AbsListView.java:3463)
  11-26 06:53:18.983: E/AndroidRuntime(1734):     at android.os.Handler.handleCallback(Handler.java:730)
  11-26 06:53:18.983: E/AndroidRuntime(1734):     at android.os.Handler.dispatchMessage(Handler.java:92)
  11-26 06:53:18.983: E/AndroidRuntime(1734):     at android.os.Looper.loop(Looper.java:137)
  11-26 06:53:18.983: E/AndroidRuntime(1734):     at android.app.ActivityThread.main(ActivityThread.java:5103)
  11-26 06:53:18.983: E/AndroidRuntime(1734):     at java.lang.reflect.Method.invokeNative(Native Method)
  11-26 06:53:18.983: E/AndroidRuntime(1734):     at java.lang.reflect.Method.invoke(Method.java:525)
  11-26 06:53:18.983: E/AndroidRuntime(1734):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
  11-26 06:53:18.983: E/AndroidRuntime(1734):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
  11-26 06:53:18.983: E/AndroidRuntime(1734):     at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>My layout:</p>
  
  <pre><code>&lt;!-- language: xml --&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:paddingBottom="@dimen/activity_vertical_margin"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  tools:context=".MainActivity" &gt;
  &lt;ImageView
      android:id="@+id/anim_image"
      android:layout_width="500sp"
      android:layout_height="500sp"/&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>