play gif in android
<p><strong>hello friends,
 i want to play Gif in android, i have tryed this code :</strong></p>

<pre><code>package com.gifOperation;

import java.io.InputStream;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Movie;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.View;

public class gifOperation extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(new GIFView(this));  
    }  
    private static class GIFView extends View {
        private static Movie movie;
        InputStream is = null;
        long moviestart;

        public GIFView(Context context) {
            super(context);
            is = context.getResources().openRawResource(R.drawable.border_gif);
            movie = Movie.decodeStream(is);
        }

        @Override
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
            long now = android.os.SystemClock.uptimeMillis();
            if (moviestart == 0) {
                moviestart = now;
            }
            int relTime = (int) ((now - moviestart) % movie.duration());
            movie.setTime(relTime);
            movie.draw(canvas, 200, 200);
            this.invalidate();
        }
    }


    }
</code></pre>

<p><strong>But got an error</strong> </p>

<pre><code>07-26 10:32:55.073: ERROR/AndroidRuntime(626): FATAL EXCEPTION: main
07-26 10:32:55.073: ERROR/AndroidRuntime(626): java.lang.NullPointerException
07-26 10:32:55.073: ERROR/AndroidRuntime(626):     at com.gifOperation.gifOperation$GIFView.onDraw(gifOperation.java:40)
07-26 10:32:55.073: ERROR/AndroidRuntime(626):     at android.view.View.draw(View.java:6740)
07-26 10:32:55.073: ERROR/AndroidRuntime(626):     at android.view.ViewGroup.drawChild(ViewGroup.java:1640)
07-26 10:32:55.073: ERROR/AndroidRuntime(626):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
07-26 10:32:55.073: ERROR/AndroidRuntime(626):     at android.view.View.draw(View.java:6743)
07-26 10:32:55.073: ERROR/AndroidRuntime(626):     at android.widget.FrameLayout.draw(FrameLayout.java:352)
07-26 10:32:55.073: ERROR/AndroidRuntime(626):     at android.view.ViewGroup.drawChild(ViewGroup.java:1640)
07-26 10:32:55.073: ERROR/AndroidRuntime(626):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
07-26 10:32:55.073: ERROR/AndroidRuntime(626):     at android.view.ViewGroup.drawChild(ViewGroup.java:1638)
07-26 10:32:55.073: ERROR/AndroidRuntime(626):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
07-26 10:32:55.073: ERROR/AndroidRuntime(626):     at android.view.View.draw(View.java:6743)
07-26 10:32:55.073: ERROR/AndroidRuntime(626):     at android.widget.FrameLayout.draw(FrameLayout.java:352)
07-26 10:32:55.073: ERROR/AndroidRuntime(626):     at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1842)
07-26 10:32:55.073: ERROR/AndroidRuntime(626):     at android.view.ViewRoot.draw(ViewRoot.java:1407)
07-26 10:32:55.073: ERROR/AndroidRuntime(626):     at android.view.ViewRoot.performTraversals(ViewRoot.java:1163)
07-26 10:32:55.073: ERROR/AndroidRuntime(626):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
07-26 10:32:55.073: ERROR/AndroidRuntime(626):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-26 10:32:55.073: ERROR/AndroidRuntime(626):     at android.os.Looper.loop(Looper.java:123)
07-26 10:32:55.073: ERROR/AndroidRuntime(626):     at android.app.ActivityThread.main(ActivityThread.java:4627)
07-26 10:32:55.073: ERROR/AndroidRuntime(626):     at java.lang.reflect.Method.invokeNative(Native Method)
07-26 10:32:55.073: ERROR/AndroidRuntime(626):     at java.lang.reflect.Method.invoke(Method.java:521)
07-26 10:32:55.073: ERROR/AndroidRuntime(626):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-26 10:32:55.073: ERROR/AndroidRuntime(626):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-26 10:32:55.073: ERROR/AndroidRuntime(626):     at dalvik.system.NativeStart.main(Native Method)
</code></pre>

<p><strong>is there any idea why this problem are raise?<br>
Thanks<br>
patel</strong></p>
