Adding listener causes crash?
<p>I have a listener interface:</p>

<pre><code>public interface AnimationListener 
{
    public void onAnimationStarted(Animation animation);
    public void onAnimationFinished(Animation animation);
    public void onAnimationCanceled(Animation animation);
}
</code></pre>

<p>This class keeps a list:</p>

<pre><code>public class AnimationManager 
{
    private List&lt;Animation&gt; animations;
    private List&lt;AnimationListener&gt; animationListeners;
    private List&lt;Animation&gt; animationsToRemove;
    private float rate;

    public AnimationManager(float rate)
    {
        setRate(rate);
    }

    public void addAnimationListener(AnimationListener listener)
    {
        animationListeners.add(listener);
    }

    public void removeAnimationListener(AnimationListener listener)
    {
        animationListeners.remove(listener);
    }
...
</code></pre>

<p>This class implements the interface:</p>

<p>public class PuzzleView extends SurfaceView implements Runnable, AnimationListener
{
...
    private AnimationManager animationManager = null;</p>

<pre><code>...

public PuzzleView(Context context) 
{
            ...
    animationManager = new AnimationManager(FRAME_RATE);
    //animationManager.addAnimationListener(this); THIS CRASHES
}
</code></pre>

<p>When I add the animation listener, it crashes. What could be wrong?</p>

<p>Thanks</p>

<blockquote>
  <p>09-21 19:15:51.433: D/AndroidRuntime(278): Shutting down VM 09-21
  19:15:51.433: W/dalvikvm(278): threadid=1: thread exiting with
  uncaught exception (group=0x4001d800) 09-21 19:15:51.453:
  E/AndroidRuntime(278): FATAL EXCEPTION: main 09-21 19:15:51.453:
  E/AndroidRuntime(278): java.lang.RuntimeException: Unable to start
  activity ComponentInfo{com.joshl.drop7/com.joshl.drop7.Game}:
  java.lang.NullPointerException 09-21 19:15:51.453:
  E/AndroidRuntime(278):    at
  android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
  09-21 19:15:51.453: E/AndroidRuntime(278):    at
  android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
  09-21 19:15:51.453: E/AndroidRuntime(278):    at
  android.app.ActivityThread.access$2300(ActivityThread.java:125) 09-21
  19:15:51.453: E/AndroidRuntime(278):  at
  android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
  09-21 19:15:51.453: E/AndroidRuntime(278):    at
  android.os.Handler.dispatchMessage(Handler.java:99) 09-21
  19:15:51.453: E/AndroidRuntime(278):  at
  android.os.Looper.loop(Looper.java:123) 09-21 19:15:51.453:
  E/AndroidRuntime(278):    at
  android.app.ActivityThread.main(ActivityThread.java:4627) 09-21
  19:15:51.453: E/AndroidRuntime(278):  at
  java.lang.reflect.Method.invokeNative(Native Method) 09-21
  19:15:51.453: E/AndroidRuntime(278):  at
  java.lang.reflect.Method.invoke(Method.java:521) 09-21 19:15:51.453:
  E/AndroidRuntime(278):    at
  com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
  09-21 19:15:51.453: E/AndroidRuntime(278):    at
  com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 09-21
  19:15:51.453: E/AndroidRuntime(278):  at
  dalvik.system.NativeStart.main(Native Method) 09-21 19:15:51.453:
  E/AndroidRuntime(278): Caused by: java.lang.NullPointerException 09-21
  19:15:51.453: E/AndroidRuntime(278):  at
  com.joshl.drop7.AnimationManager.addAnimationListener(AnimationManager.java:19)
  09-21 19:15:51.453: E/AndroidRuntime(278):    at
  com.joshl.drop7.PuzzleView.(PuzzleView.java:82) 09-21
  19:15:51.453: E/AndroidRuntime(278):  at
  com.joshl.drop7.Game.onCreate(Game.java:18) 09-21 19:15:51.453:
  E/AndroidRuntime(278):    at
  android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
  09-21 19:15:51.453: E/AndroidRuntime(278):    at
  android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
  09-21 19:15:51.453: E/AndroidRuntime(278):    ... 11 more 09-21
  19:15:53.333: I/Process(278): Sending signal. PID: 278 SIG: 9</p>
</blockquote>
