title: FATAL EXCEPTION: java.lang.RuntimeException: Unable to instantiate service
body: <p>I am beginner in android. i create a new service and run it in android mobile API Level-23. when i press button to startservice it show me ERROR. now i Create new project but problem is same there.</p>
  
  <pre><code>**FATAL EXCEPTION: java.lang.RuntimeException: Unable to instantiate service com.example.uzair.servicesapp.myIntentService: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference** 
  </code></pre>
  
  <p>MainActivity.java</p>
  
  <pre><code>import android.content.Intent;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.view.Gravity;
  import android.view.View;
  import android.widget.Toast;
  
  public class MainActivity extends AppCompatActivity {
  
      private static int i =0;
      private Intent  ii;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          ii = new Intent(this,myIntentService.class);
         Toast.makeText(this, "this is custom toast", Toast.LENGTH_SHORT).show();
   }
  
      public void clickme2(View view)
      {
          startService(ii);
          Toast.makeText(this, " Service start toast", Toast.LENGTH_SHORT).show();
      }
  
      public void clickme(View view) {
  
   stopService(ii);
  Toast.makeText(this, "Service stop toast", Toast.LENGTH_SHORT).show(); 
          i++;
      }
  }
  </code></pre>
  
  <p>MyIntentService.java</p>
  
  <pre><code>import android.app.IntentService;
  import android.content.Intent;
  import android.widget.Toast;
  public class myIntentService extends IntentService {
  
      public myIntentService()
      {
          super("myIntentService");
          Toast.makeText(this, "IntentService Constuctor toast", Toast.LENGTH_SHORT);
      }
  
      @Override
      protected void onHandleIntent(Intent intent) {
          Toast.makeText(this, "OnhandleIntent toast", Toast.LENGTH_SHORT);
      }
  
      @Override
      public void onDestroy() {
          super.onDestroy();
          Toast.makeText(this, "Destroy toast", Toast.LENGTH_SHORT);
      }
  
      @Override
      public void onCreate() {
          super.onCreate();
      }
  }
  </code></pre>
  
  <p>AndroidManifest.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.uzair.servicesapp"&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@mipmap/ic_launcher"
          android:label="@string/app_name"
          android:supportsRtl="true"
          android:theme="@style/AppTheme"&gt;
          &lt;activity android:name=".MainActivity"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;service android:name=".myIntentService"/&gt;
  
  
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>activity_main.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:paddingBottom="@dimen/activity_vertical_margin"
      android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      tools:context="com.example.uzair.servicesapp.MainActivity"&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Hello World!"
          android:id="@+id/textView" /&gt;
  
      &lt;Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:onClick="clickme"
          android:text="@string/click_me"
          android:layout_alignParentBottom="true"
          android:layout_centerHorizontal="true"
          android:layout_marginBottom="118dp" /&gt;
  
      &lt;Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="New Button"
          android:id="@+id/button"
          android:layout_centerVertical="true"
          android:layout_centerHorizontal="true"
          android:onClick="clickme2" /&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>