title: java.lang.RuntimeException: Unable to start service java.lang.NullPointerException
body: <p>This is my first app using service. Getting java.lang.RuntimeException: Unable to start service java.lang.NullPointerException. My intention is to send sms when device is in suspend state.</p>
  
  <p><strong>SENDSMS.java</strong></p>
  
  <pre><code>package com.qualcomm.sendsms;
  
  import android.os.Bundle;
  import android.app.Activity;
  import android.content.Intent;
  import android.util.Log;
  import android.view.Menu;
  
  public class SENDSMS extends Activity {
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_sendsms);
      String phone_num =  null;
      String sms = null;
      String sleep_time = null;
      Bundle extras = getIntent().getExtras();
      if (extras != null) {
          phone_num = extras.getString("Phone_Number");
          Log.e("????????????????SEND_SMS", "phno : "+phone_num);
          sms = extras.getString("SMS_Body");
          Log.e("????????????????SEND_SMS", "sms : "+sms);
          sleep_time = extras.getString("Sleep_Time");
          Log.e("????????????????Sleep_Time", "sleep_time : "+sleep_time);
          Intent myIntent = new Intent(this, sendservicesms.class);
          myIntent.putExtra("Phone_Number",phone_num);
          myIntent.putExtra("SMS_Body",sms);
          myIntent.putExtra("Sleep_Time",sleep_time);
          startService(myIntent);
      }
      finish();
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.sendsm, menu);
      return true;
  }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>Service : sendservicesms.java</strong></p>
  
  <pre><code> package com.qualcomm.sendsms;
  
   import android.app.IntentService;
   import android.content.Intent;
   import android.os.Bundle;
   import android.os.IBinder;
   import android.telephony.SmsManager;
   import android.util.Log;
   import android.widget.Toast;
  
   public class sendservicesms extends IntentService  {
  int mStartMode;       // indicates how to behave if the service is killed
  IBinder mBinder;      // interface for clients that bind
  boolean mAllowRebind; // indicates whether onRebind should be used
  
  public sendservicesms() {
      super("sendservicesms");
    }
  public void onCreate() {
      // The service is being created
  
  }
  @Override
  protected void onHandleIntent(Intent intent) { 
      // The service is starting, due to a call to startService()
       if(intent!=null) {
      Bundle param = intent.getExtras();
      if (param != null) {
      String phone_no = (String)param.get("Phone_Number");
      String sms_body = (String)param.get("SMS_Body");
      String sleeptime = (String)param.get("Sleep_Time");
      Log.e("????????????????SEND_SMS", "phno : "+phone_no);
      Log.e("????????????????SEND_SMS", "sms : "+sms_body);
      Log.e("????????????????Sleep_Time", "sleep_time : "+sleeptime);
      Long time = Long.parseLong(sleeptime);
      Log.e("????????????????time long", "Long_time : "+time);
      try {
          if(sleeptime!=null &amp;&amp; sleeptime.length() &gt; 0){
              Thread.sleep(Long.parseLong(sleeptime));
          }
          Log.e("????????????????Sleep happened well", "sleep_time : "+sleeptime);
          SmsManager smsManager = SmsManager.getDefault();
          smsManager.sendTextMessage(phone_no, null, sms_body, null, null);
          Toast.makeText(getApplicationContext(), "SMS Sent!",
                  Toast.LENGTH_LONG).show();
      } catch (Exception e) {
          Toast.makeText(getApplicationContext(),
                  "SMS faild, please try again later!",
                  Toast.LENGTH_LONG).show();
          e.printStackTrace();
      }
      }
       }
  
  }
  @Override
  public IBinder onBind(Intent intent) {
      // A client is binding to the service with bindService()
      return mBinder;
  }
  @Override
  public boolean onUnbind(Intent intent) {
      // All clients have unbound with unbindService()
      return mAllowRebind;
  }
  @Override
  public void onRebind(Intent intent) {
      // A client is binding to the service with bindService(),
      // after onUnbind() has already been called
  }
  @Override
  public void onDestroy() {
      // The service is no longer used and is being destroyed
  }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>LOGCAT:</strong></p>
  
  <pre><code>E/AndroidRuntime(10276): FATAL EXCEPTION: main
  E/AndroidRuntime(10276): java.lang.RuntimeException: Unable to start service com.qualcomm.sendsms.sendservicesms@418dd170 with Intent { cmp=com.qualcomm.sendsms/.sendservicesms (has extras) }: java.lang.NullPointerException
  E/AndroidRuntime(10276):        at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2676)
  E/AndroidRuntime(10276):        at android.app.ActivityThread.access$1900(ActivityThread.java:144)
  E/AndroidRuntime(10276):        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1334)
  E/AndroidRuntime(10276):        at android.os.Handler.dispatchMessage(Handler.java:99)
  E/AndroidRuntime(10276):        at android.os.Looper.loop(Looper.java:137)
  E/AndroidRuntime(10276):        at android.app.ActivityThread.main(ActivityThread.java:5074)
  E/AndroidRuntime(10276):        at java.lang.reflect.Method.invokeNative(Native Method)
  E/AndroidRuntime(10276):        at java.lang.reflect.Method.invoke(Method.java:511)
  E/AndroidRuntime(10276):        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
  E/AndroidRuntime(10276):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
  E/AndroidRuntime(10276):        at dalvik.system.NativeStart.main(Native Method)
  E/AndroidRuntime(10276): Caused by: java.lang.NullPointerException
  E/AndroidRuntime(10276):        at android.app.IntentService.onStart(IntentService.java:116)
  E/AndroidRuntime(10276):        at android.app.IntentService.onStartCommand(IntentService.java:130)
  E/AndroidRuntime(10276):        at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2659)
  </code></pre>