title: NullPointerException: Attempt to invoke virtual method android.content.Context.getApplicationContext()' on a null object reference
body: <p>I have a Main-Activity, which looks like:</p>
  
  <pre><code>public class MainActivity extends Activity {
  
  ExpandableListAdapter listAdapter;
  ExpandableListView expListView;  
  WeaponList listData = new WeaponList();
  public static StatusCheck checkBombStatus = new StatusCheck();
  String weapon = null;
  Intent openGameplay;
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);  
      setContentView(R.layout.main);
  
      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
  
      // get the listview
      expListView = (ExpandableListView) findViewById(R.id.expandableListView1);
  
      // preparing list data
      listData.prepareWeaponList();
  
      listAdapter = new ExpandableListAdapter(this, listData.listDataHeader, listData.listDataChild);
  
      // setting list adapter
      expListView.setAdapter(listAdapter);
  
      //collapse all child-items from the listview
      collapseItems();
  
      // Listview on child click listener       
      expListView.setOnChildClickListener(new OnChildClickListener() {
  
          @Override
          public boolean onChildClick(ExpandableListView parent, View v,
                                      int groupPosition, int childPosition, long id) {
              weapon = listData.listDataChild.get(listData.listDataHeader.get(groupPosition)).get(childPosition);
  
              openGameplay = new Intent(MainActivity.this, GamePlay.class);
              openGameplay.putExtra("weapon", weapon);
              startActivity(openGameplay);
  
              return false;
          }
      });
  }
  
  private void collapseItems() {
  
      expListView.expandGroup(0);
      expListView.expandGroup(1);
      expListView.expandGroup(2);
      expListView.expandGroup(3);
      expListView.expandGroup(4);
      expListView.expandGroup(5);
      expListView.expandGroup(6);
      expListView.expandGroup(7);
  }
  
  
  
  
  public void exitApplication() {
      this.finish();
  }
  </code></pre>
  
  <p>and my second Activity:</p>
  
  <pre><code>public class GamePlay extends Activity {
  ...
  static MediaPlayer mediaPlayer = new MediaPlayer();
  static SoundPool soundPool;
  static boolean loaded = false;
  private static Context mContext;
  public static StatusCheck statusCheck;
  
   public static Context getContext() {
         return mContext;
   }
  
      public void setContext(Context mContext) {
          GamePlay.mContext = mContext;
   }
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.gameplay);
  
      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
  
      Bundle extras = getIntent().getExtras();    
  
      ....    
  
      loadweapon(weapon = extras.getString("weapon"));
      loadsound();
  
      imageView.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View v) {
  
              if(j == 1) {
                  playAudioFromMediaPlayer();
  
              }
  
              else {
                  //MediaPlayerService.loadAudioToSoundPool(getApplicationContext(), 54);
              }
          }
      });
  
      reload.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View v) {
              ...
          }
      });
  }
  
  
  private void loadweapon(String weapon) {
  
      if() ....
  }
  
  
  private void loadsound() {
      if(j == 1 &amp;&amp; soundID != 29) {
  
          loadAudioToMediaPlayer(soundID);
      }
      else {
  
          loadAudioToSoundPool(soundID);
      }
  }
  
  
  public static void loadAudioToMediaPlayer(int id) {
  
      soundID = id;
      mediaPlayer = MediaPlayer.create(mContext.getApplicationContext(), SoundList.soundListfire.get(id));
  }
  
  public static void loadAudioToSoundPool(int id) {
  
    soundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() {
        @Override
        public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
          loaded = true;
        }
  });
    soundID = soundPool.load(mContext.getApplicationContext(), SoundList.soundListfire.get(id), 1);
  }
  
  ....
  }
  </code></pre>
  
  <p>I am having the following exception when I click on the <code>Imageview</code>:</p>
  
  <pre><code>03-11 12:01:20.199: E/AndroidRuntime(8929): java.lang.RuntimeException: Unable to start activity ComponentInfo{....GamePlay}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.content.Context.getApplicationContext()' on a null object reference
  03-11 12:01:20.199: E/AndroidRuntime(8929):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2329)
  03-11 12:01:20.199: E/AndroidRuntime(8929):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2391)
  03-11 12:01:20.199: E/AndroidRuntime(8929):     at android.app.ActivityThread.access$900(ActivityThread.java:147)
  03-11 12:01:20.199: E/AndroidRuntime(8929):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1296)
  03-11 12:01:20.199: E/AndroidRuntime(8929):     at android.os.Handler.dispatchMessage(Handler.java:102)
  03-11 12:01:20.199: E/AndroidRuntime(8929):     at android.os.Looper.loop(Looper.java:135)
  03-11 12:01:20.199: E/AndroidRuntime(8929):     at android.app.ActivityThread.main(ActivityThread.java:5256)
  03-11 12:01:20.199: E/AndroidRuntime(8929):     at java.lang.reflect.Method.invoke(Native Method)
  03-11 12:01:20.199: E/AndroidRuntime(8929):     at java.lang.reflect.Method.invoke(Method.java:372)
  03-11 12:01:20.199: E/AndroidRuntime(8929):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
  03-11 12:01:20.199: E/AndroidRuntime(8929):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
  03-11 12:01:20.199: E/AndroidRuntime(8929): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.content.Context.getApplicationContext()' on a null object reference
  03-11 12:01:20.199: E/AndroidRuntime(8929):     at cs16.tacticalguns.GamePlay.loadAudioToMediaPlayer(GamePlay.java:442)
  03-11 12:01:20.199: E/AndroidRuntime(8929):     at cs16.tacticalguns.GamePlay.loadsound(GamePlay.java:423)
  03-11 12:01:20.199: E/AndroidRuntime(8929):     at cs16.tacticalguns.GamePlay.onCreate(GamePlay.java:72)
  03-11 12:01:20.199: E/AndroidRuntime(8929):     at android.app.Activity.performCreate(Activity.java:5938)
  03-11 12:01:20.199: E/AndroidRuntime(8929):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
  03-11 12:01:20.199: E/AndroidRuntime(8929):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2282)
  03-11 12:01:20.199: E/AndroidRuntime(8929):     ... 10 more
  </code></pre>
  
  <p>I tried to replace <code>mContext.getApplicationContext()</code> with <code>this</code> or <code>Gameplay.this</code>, but then I had the error <code>Cannot use this in a static context</code>. What I am doing wrong and how can I fix it?</p>