title: Unable to start receiver java.lang.NullPointerException
body: <p>Trying to make a widget that will pick a random audio out of 3 and play with a widget. Getiing a error "Unable to start receiver" any help would be great!</p>
  
  <p>Line 40 = mp=MediaPlayer.create(context.getApplicationContext(), mfile[rnd.nextInt(NUM_SOUND_FILES)]);</p>
  
  <p>Code:</p>
  
  <pre><code>public class MyWidget extends AppWidgetProvider {
  
    public static String ACTION_WIDGET_RECEIVER = "ActionReceiverWidget";
    private MediaPlayer mp;
    private final int NUM_SOUND_FILES = 3;  //*****REPLACE THIS WITH THE ACTUAL NUMBER OF SOUND FILES YOU HAVE*****
      private int mfile[] = new int[NUM_SOUND_FILES];
      private Random rnd = new Random();
  
  
  
    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
         RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
         Intent active = new Intent(context, MyWidget.class);
         active.setAction(ACTION_WIDGET_RECEIVER);
         PendingIntent actionPendingIntent = PendingIntent.getBroadcast(context, 0, active, 0);
         remoteViews.setOnClickPendingIntent(R.id.pauseicon, actionPendingIntent);
         appWidgetManager.updateAppWidget(appWidgetIds, remoteViews);
    }
  
    @Override
    public void onReceive(Context context, Intent intent)
    {
        mfile[0] = R.raw.sound04;  //****REPLACE THESE WITH THE PROPER NAMES OF YOUR SOUND FILES
        mfile[1] = R.raw.sound05;  //PLACE THE SOUND FILES IN THE /res/raw/ FOLDER IN YOUR PROJECT*****
        mfile[2] = R.raw.sound06;
  
        if (mp == null)
            mp=MediaPlayer.create(context.getApplicationContext(), mfile[rnd.nextInt(NUM_SOUND_FILES)]);
        final String action = intent.getAction();
  
        if (ACTION_WIDGET_RECEIVER.equals(action)) {
             if (mp.isPlaying())
                 mp.stop(); 
              else
                  mp.start();
  
         }
        super.onReceive(context, intent);
  
   }
  
  }
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>02-13 17:50:20.610: E/AndroidRuntime(2663): FATAL EXCEPTION: main
  02-13 17:50:20.610: E/AndroidRuntime(2663): java.lang.RuntimeException: Unable to start receiver com.app.test: java.lang.NullPointerException
  02-13 17:50:20.610: E/AndroidRuntime(2663):     at android.app.ActivityThread.handleReceiver(ActivityThread.java:2431)
  02-13 17:50:20.610: E/AndroidRuntime(2663):     at     android.app.ActivityThread.access$1500(ActivityThread.java:141)
  02-13 17:50:20.610: E/AndroidRuntime(2663):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1332)
  02-13 17:50:20.610: E/AndroidRuntime(2663):     at android.os.Handler.dispatchMessage(Handler.java:99)
  02-13 17:50:20.610: E/AndroidRuntime(2663):     at android.os.Looper.loop(Looper.java:137)
   02-13 17:50:20.610: E/AndroidRuntime(2663):    at android.app.ActivityThread.main(ActivityThread.java:5103)
   02-13 17:50:20.610: E/AndroidRuntime(2663):    at java.lang.reflect.Method.invokeNative(Native Method)
   02-13 17:50:20.610: E/AndroidRuntime(2663):    at java.lang.reflect.Method.invoke(Method.java:525)
   02-13 17:50:20.610: E/AndroidRuntime(2663):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
   02-13 17:50:20.610: E/AndroidRuntime(2663):    at      com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
   02-13 17:50:20.610: E/AndroidRuntime(2663):    at dalvik.system.NativeStart.main(Native Method)
   02-13 17:50:20.610: E/AndroidRuntime(2663): Caused by: java.lang.NullPointerException
   02-13 17:50:20.610: E/AndroidRuntime(2663):    at com.app.test.MyWidget.onReceive(MyWidget.java:40)
   02-13 17:50:20.610: E/AndroidRuntime(2663):    at android.app.ActivityThread.handleReceiver(ActivityThread.java:2424)
   02-13 17:50:20.610: E/AndroidRuntime(2663):    ... 10 more
  </code></pre>