title: Nullpointerexception at onStop() method
body: <p>I used this sample code in a similar clock application:
  <a href="http://about-android.blogspot.in/2010/04/create-apps-to-show-digital-time-in_19.html" rel="nofollow">http://about-android.blogspot.in/2010/04/create-apps-to-show-digital-time-in_19.html</a></p>
  
  <p>It works fine, however when using the back or home buttons I get a nullpointerexception in the log. It says unable to stop application.
  If I remove the methods :</p>
  
  <p><code>timer.cancel();<br>
  timer.purge();<br>
  timer = null;</code></p>
  
  <p>It works OK, but I suppose this would be memory consuming?
  /M </p>
  
  <blockquote>
    <p>08-19 19:00:13.438: E/AndroidRuntime(1064): FATAL EXCEPTION: main<br>
    08-19 19:00:13.438: E/AndroidRuntime(1064): java.lang.RuntimeException: Unable to stop activity {se.macke.binarycounter/se.macke.binarycounter.MainActivity}: java.lang.NullPointerException<br>
    08-19 19:00:13.438: E/AndroidRuntime(1064):     at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:2624)<br>
    08-19 19:00:13.438: E/AndroidRuntime(1064):     at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:2690)<br>
    08-19 19:00:13.438: E/AndroidRuntime(1064):     at android.app.ActivityThread.access$2100(ActivityThread.java:117)<br>
    08-19 19:00:13.438: E/AndroidRuntime(1064):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:964)<br>
    08-19 19:00:13.438: E/AndroidRuntime(1064):     at android.os.Handler.dispatchMessage(Handler.java:99)<br>
    08-19 19:00:13.438: E/AndroidRuntime(1064):     at android.os.Looper.loop(Looper.java:123)<br>
    08-19 19:00:13.438: E/AndroidRuntime(1064):     at android.app.ActivityThread.main(ActivityThread.java:3683)<br>
    08-19 19:00:13.438: E/AndroidRuntime(1064):     at java.lang.reflect.Method.invokeNative(Native Method)<br>
    08-19 19:00:13.438: E/AndroidRuntime(1064):     at java.lang.reflect.Method.invoke(Method.java:507)<br>
    08-19 19:00:13.438: E/AndroidRuntime(1064):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)<br>
    08-19 19:00:13.438: E/AndroidRuntime(1064):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)<br>
    08-19 19:00:13.438: E/AndroidRuntime(1064):     at dalvik.system.NativeStart.main(Native Method)<br>
    08-19 19:00:13.438: E/AndroidRuntime(1064): Caused by: java.lang.NullPointerException
    08-19 19:00:13.438: E/AndroidRuntime(1064):     at se.macke.binarycounter.MainActivity.onStop(MainActivity.java:209)<br>
    08-19 19:00:13.438: E/AndroidRuntime(1064):     at android.app.Instrumentation.callActivityOnStop(Instrumentation.java:1170)<br>
    08-19 19:00:13.438: E/AndroidRuntime(1064):     at android.app.Activity.performStop(Activity.java:3873)<br>
    08-19 19:00:13.438: E/AndroidRuntime(1064):     at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:2619)<br>
    08-19 19:00:13.438: E/AndroidRuntime(1064):     ... 11 more<br>
    08-19 19:00:16.398: I/Process(1064): Sending signal. PID: 1064 SIG: 9
    08-19 19:00:16.450: I/ActivityManager(61): Process se.macke.binarycounter (pid 1064) has died.
    08-19 19:00:16.450: E/InputDispatcher(61): channel '4079da00 se.macke.binarycounter/se.macke.binarycounter.MainActivity (server)' ~ Consumer closed input channel or an error occurred.  events=0x8<br>
    08-19 19:00:16.450: E/InputDispatcher(61): channel '4079da00 se.macke.binarycounter/se.macke.binarycounter.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!  </p>
  </blockquote>