title: Toast in Broadcast receiver
body: <p>I am trying a simple code to display caller number as toast whenever a call is received.</p>
  
  <p>I get the following error:</p>
  
  <pre><code> 03-11 13:34:41.143: E/AndroidRuntime(27141): java.lang.NullPointerException
   03-11 13:34:41.143: E/AndroidRuntime(27141):   at android.widget.Toast.&lt;init&gt;(Toast.java:93)
   03-11 13:34:41.143: E/AndroidRuntime(27141):   at android.widget.Toast.makeText(Toast.java:241)
   03-11 13:34:41.143: E/AndroidRuntime(27141):   at com.demotest.ringer.PhoneListenerBroad$MyPhoneStateListener.onCallStateChanged(PhoneListenerBroad.java:47)
   03-11 13:34:41.143: E/AndroidRuntime(27141):   at android.telephony.PhoneStateListener$2.handleMessage(PhoneStateListener.java:369)
   03-11 13:34:41.143: E/AndroidRuntime(27141):   at android.os.Handler.dispatchMessage(Handler.java:102)
   03-11 13:34:41.143: E/AndroidRuntime(27141):   at android.os.Looper.loop(Looper.java:136)
   03-11 13:34:41.143: E/AndroidRuntime(27141):   at android.app.ActivityThread.main(ActivityThread.java:5017)
   03-11 13:34:41.143: E/AndroidRuntime(27141):   at java.lang.reflect.Method.invokeNative(Native Method)
   03-11 13:34:41.143: E/AndroidRuntime(27141):   at java.lang.reflect.Method.invoke(Method.java:515)
   03-11 13:34:41.143: E/AndroidRuntime(27141):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
   03-11 13:34:41.143: E/AndroidRuntime(27141):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
   03-11 13:34:41.143: E/AndroidRuntime(27141):   at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>Below is the code I am trying:</p>
  
  <pre><code> public class PhoneListenerBroad extends BroadcastReceiver  
    { 
      @Override
  public void onReceive(Context context, Intent intent) 
  {
      try 
      {
          // TELEPHONY MANAGER class object to register one listner
          TelephonyManager tmgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
  
          //Create Listner
          MyPhoneStateListener PhoneListener = new MyPhoneStateListener();
  
          // Register listener for LISTEN_CALL_STATE
          tmgr.listen(PhoneListener, PhoneStateListener.LISTEN_CALL_STATE);
  
      } 
      catch (Exception e) 
      {
          Log.e("Phone Receive Error", " " + e);
      }
  
  }
  
  private class MyPhoneStateListener extends PhoneStateListener 
  {
      private Context context;
  
      public void onCallStateChanged(int state, String incomingNumber) 
      {
  
          Log.e("MyPhoneListener",state+"   incoming no:"+incomingNumber);
  
          if (state == 1) 
          {
              String msg = "New Phone Call Event. Incomming Number : "+incomingNumber;
              Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
          }
      }
  }
  }
  </code></pre>
  
  <p>Manifest has required permissions and declarations.. I am not sure where I am going wrong?</p>