title: extends Application example causing program to crash
body: <p>I followed this example:</p>
  <p><a href="http://www.intridea.com/blog/2011/5/24/how-to-use-application-object-of-android" rel="nofollow noreferrer">http://www.intridea.com/blog/2011/5/24/how-to-use-application-object-of-android</a></p>
  <p>It seems like it's crashing during <code>onCreate()</code> of <code>MyApplication</code> when
  <code>singleton = this</code>.</p>
  <pre><code>public class MyApplication extends Application {
  
  @Override
  public void onConfigurationChanged(Configuration newConfig) {
      super.onConfigurationChanged(newConfig);
  }
  private static MyApplication singleton;
  
  @Override
  public void onCreate() {
      super.onCreate();
      Log.v(&quot;MyApplication&quot;, &quot;Hi from my application&quot;);
      singleton = this;
      Log.v(&quot;MyApplication&quot;, &quot;End onCreat of myApplicatoin&quot;);
      
  }
  @Override
  public void onLowMemory() {
      super.onLowMemory();
  }
  
  @Override
  public void onTerminate() {
      super.onTerminate();
  }
  
  public MyApplication getInstance(){
      return singleton;
  }
  public boolean isNetworkAvailable() {
      return true;
  }
  
  
  }
  </code></pre>
  <p>Code from MainActivity:</p>
  <pre><code>MyApplication mApplication = (MyApplication) getApplicationContext();
  </code></pre>
  <p>Here are the logcat messages :</p>
  <pre><code>11-23 16:43:01.398: V/MyApplication(30957): Hi from my application
  11-23 16:43:01.398: E/AndroidRuntime(30957): FATAL EXCEPTION: main
  11-23 16:43:01.398: E/AndroidRuntime(30957): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.jimmyc.fall12.OpenClass/com.jimmyc.fall12.OpenClass.MainInterface}: java.lang.NullPointerException
  11-23 16:43:01.398: E/AndroidRuntime(30957):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
  11-23 16:43:01.398: E/AndroidRuntime(30957):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
  11-23 16:43:01.398: E/AndroidRuntime(30957):    at android.app.ActivityThread.access$600(ActivityThread.java:141)
  11-23 16:43:01.398: E/AndroidRuntime(30957):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
  11-23 16:43:01.398: E/AndroidRuntime(30957):    at android.os.Handler.dispatchMessage(Handler.java:99)
  11-23 16:43:01.398: E/AndroidRuntime(30957):    at android.os.Looper.loop(Looper.java:137)
  11-23 16:43:01.398: E/AndroidRuntime(30957):    at android.app.ActivityThread.main(ActivityThread.java:5039)
  11-23 16:43:01.398: E/AndroidRuntime(30957):    at java.lang.reflect.Method.invokeNative(Native Method)
  11-23 16:43:01.398: E/AndroidRuntime(30957):    at java.lang.reflect.Method.invoke(Method.java:511)
  11-23 16:43:01.398: E/AndroidRuntime(30957):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
  11-23 16:43:01.398: E/AndroidRuntime(30957):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
  11-23 16:43:01.398: E/AndroidRuntime(30957):    at dalvik.system.NativeStart.main(Native Method)
  11-23 16:43:01.398: E/AndroidRuntime(30957): Caused by: java.lang.NullPointerException
  11-23 16:43:01.398: E/AndroidRuntime(30957):    at android.content.ContextWrapper.getApplicationContext(ContextWrapper.java:109)
  11-23 16:43:01.398: E/AndroidRuntime(30957):    at com.jimmyc.fall12.OpenClass.MainInterface.&lt;init&gt;(MainInterface.java:75)
  11-23 16:43:01.398: E/AndroidRuntime(30957):    at java.lang.Class.newInstanceImpl(Native Method)
  11-23 16:43:01.398: E/AndroidRuntime(30957):    at java.lang.Class.newInstance(Class.java:1319)
  11-23 16:43:01.398: E/AndroidRuntime(30957):    at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
  11-23 16:43:01.398: E/AndroidRuntime(30957):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
  &gt; 11-23 16:43:01.398: E/AndroidRuntime(30957):  ... 11 more
  </code></pre>
  <p>Any ideas?</p>
  <p>Lines 74, 75, 76 of MainInterface</p>
  <blockquote>
  <p>74: ////////////////Access to global function</p>
  <p>75: MyApplication mApplication = (MyApplication) getApplicationContext();</p>
  <p>76: //</p>
  </blockquote>