title: adb shell am broadcast - BroadcastReceiver throws nullpointer
body: <p>I'm trying to launch this command:</p>
  
  <pre><code>adb shell am broadcast -a android.provider.Telephony.SMS_RECEIVED --es sms_body "TEXTTEXTTEXT"   -n com.example.name/.receivers.SmsReceiver
  </code></pre>
  
  <p>And this code throws null pointer exception:</p>
  
  <p>public class SmsReceiver extends BroadcastReceiver {</p>
  
  <pre><code>...
  
  private Context mContext;
  private Intent mIntent;
  
  public void onReceive(Context context, Intent intent) {
      mContext = context;
      mIntent = intent;
  
      String action = intent.getAction();
      if (action.equals(Const.ACTION_SMS_RECEIVED)) {
          String address = "", str = "";
  
          SmsMessage[] msgs = getMessagesFromIntent(mIntent);
  
          ...
  
      }
  }
  
  public static SmsMessage[] getMessagesFromIntent (Intent intent){
          Object[] messages = (Object[]) intent.getSerializableExtra("pdus");
          byte[][] pduObjs = new byte[messages.length][];
  
          for (int i = 0; i &lt; messages.length; i++) {
              pduObjs[i] = (byte[]) messages[i];
          }
  
          byte[][] pdus = new byte[pduObjs.length][];
          int pduCount = pdus.length;
          SmsMessage[] msgs = new SmsMessage[pduCount];
          for (int i = 0; i &lt; pduCount; i++) {
              pdus[i] = pduObjs[i];
              msgs[i] = SmsMessage.createFromPdu(pdus[i]);
          }
          return msgs;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>And here is the console output: </p>
  
  <pre><code>12-30 15:48:34.724  26032-26032/com.example.name E/AndroidRuntime﹕ FATAL EXCEPTION: main
      Process: com.example.name, PID: 26032
      java.lang.RuntimeException: Unable to start receiver com.example.name.receivers.SmsReceiver: java.lang.NullPointerException
              at android.app.ActivityThread.handleReceiver(ActivityThread.java:2567)
              at android.app.ActivityThread.access$1800(ActivityThread.java:161)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1341)
              at android.os.Handler.dispatchMessage(Handler.java:102)
              at android.os.Looper.loop(Looper.java:157)
              at android.app.ActivityThread.main(ActivityThread.java:5356)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:515)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
              at dalvik.system.NativeStart.main(Native Method)
       Caused by: java.lang.NullPointerException
              at com.example.name.receivers.SmsReceiver.getMessagesFromIntent(SmsReceiver.java:60)
              at com.example.name.receivers.SmsReceiver.onReceive(SmsReceiver.java:30)
              at android.app.ActivityThread.handleReceiver(ActivityThread.java:2552)
              at android.app.ActivityThread.access$1800(ActivityThread.java:161)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1341)
              at android.os.Handler.dispatchMessage(Handler.java:102)
              at android.os.Looper.loop(Looper.java:157)
              at android.app.ActivityThread.main(ActivityThread.java:5356)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:515)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
              at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>Now, here is the tricky part. 
  My code inside SmsReceiver works for normal SMS messages. When I try to "simulate" this problem, I get this error. Probalby I mixed up something with adb command. I tried to fix it myself, but no luck. Do you have any idea what I did wrong?</p>