android.app.ActivityThread.getApplicationThread()' on a null object reference
<p>The microhonePopUp method will work in MainActivity, but I'd like for it to work from another class (MediaButtonIntentReceiver).  The problem is with startActivityForResult(intent, REQUEST_CODE); - but I don't know how to resolve it.</p>

<p>in the MainActivity class</p>

<pre><code>public void microphonePopUp(){
        Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Voice your answer");
        startActivityForResult(intent, REQUEST_CODE);
    }
</code></pre>

<p>in the MediaButtonIntentReceiver class</p>

<pre><code>public class MediaButtonIntentReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {

        if (Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())) {
            KeyEvent event = (KeyEvent)intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
            if (KeyEvent.KEYCODE_HEADSETHOOK == event.getKeyCode()) {
                MainActivity test = new MainActivity(); 
                test.microphonePopUp();
            }
        }
    }
}
</code></pre>

<blockquote>
  <p>12-09 11:20:14.803 19556-19556/com.timtennyson.priceaddition
  E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                 Process: com.timtennyson.priceaddition, PID: 19556
                                                                                 java.lang.RuntimeException: Unable to start receiver
  com.timtennyson.priceaddition.MediaButtonIntentReceiver:
  java.lang.NullPointerException: Attempt to invoke virtual method
  'android.app.ActivityThread$ApplicationThread
  android.app.ActivityThread.getApplicationThread()' on a null object
  reference
                                                                                     at android.app.ActivityThread.handleReceiver(ActivityThread.java:3641)
                                                                                     at android.app.ActivityThread.access$2000(ActivityThread.java:221)
                                                                                     at
  android.app.ActivityThread$H.handleMessage(ActivityThread.java:1876)
                                                                                     at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                     at android.os.Looper.loop(Looper.java:158)
                                                                                     at android.app.ActivityThread.main(ActivityThread.java:7224)
                                                                                     at java.lang.reflect.Method.invoke(Native Method)
                                                                                     at
  com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                                                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
                                                                                  Caused by: java.lang.NullPointerException: Attempt to invoke virtual
  method 'android.app.ActivityThread$ApplicationThread
  android.app.ActivityThread.getApplicationThread()' on a null object
  reference
                                                                                     at android.app.Activity.startActivityForResult(Activity.java:4283)
                                                                                     at android.app.Activity.startActivityForResult(Activity.java:4230)
                                                                                     at
  android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:842)
                                                                                     at
  com.timtennyson.priceaddition.MainActivity.microphonePopUp(MainActivity.java:103)
                                                                                     at
  com.timtennyson.priceaddition.MediaButtonIntentReceiver.onReceive(MediaButtonIntentReceiver.java:27)
                                                                                     at android.app.ActivityThread.handleReceiver(ActivityThread.java:3634)
                                                                                     at android.app.ActivityThread.access$2000(ActivityThread.java:221) 
                                                                                     at
  android.app.ActivityThread$H.handleMessage(ActivityThread.java:1876) 
                                                                                     at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                     at android.os.Looper.loop(Looper.java:158) 
                                                                                     at android.app.ActivityThread.main(ActivityThread.java:7224) 
                                                                                     at java.lang.reflect.Method.invoke(Native Method)</p>
</blockquote>