title: Unable to Instantiate Service - Java.NullPointerException
body: <p>so basically I'm rather new to android development and I want to create an application that runs in the background. I have decided to use Service as I need the application to constantly be grabbing information regarding Wifi as long as the toggle button remains on in the application itself. The service will be turned off if the toggle button is off.</p>
  
  <p>However, I have been having a LOT of trouble getting the service to even run, and the error that comes up is the one specified in the title. </p>
  
  <p>Can anyone help me figure this out?</p>
  
  <p>Here is my manifest. The reason why you see other activities here is because I'm trying to migrate my previous program which didn't run in the background into a service that runs in the background. So right now the only activity I use is Main Activity that has a toggle button, and the service class. </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.wifianalysis"
      android:versionCode="1"
      android:versionName="1.0" &gt;
  
      &lt;uses-permission android:name="android.permission.ACCESS_WIFI_STATE"&gt;&lt;/uses-permission&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"&gt;&lt;/uses-     permission&gt;
      &lt;uses-permission android:name="android.permission.CHANGE_WIFI_STATE"&gt;&lt;/uses-permission&gt;
      &lt;uses-permission android:name="android.permission.WAKE_LOCK"&gt;&lt;/uses-permission&gt;
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
      &lt;uses-permission android:name="com.android.alarm.permission.SET_ALARM"/&gt;
      &lt;uses-feature android:name="android.hardware.wifi" /&gt;
      &lt;uses-sdk
          android:minSdkVersion="8"
          android:targetSdkVersion="19" /&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" &gt;
  
          &lt;!--
              Because android:exported is set to "false",
              the service is only available to this app.
          --&gt;
          &lt;service
          android:name=".WifiPullService"
          android:label="Wifi Pull Service" &gt;
      &lt;/service&gt;
  
  
          &lt;activity
              android:name="com.example.wifianalysis.MainActivity"
              android:label="@string/app_name" &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;activity
              android:name="com.example.wifianalysis.Checkwifi"
              android:label="@string/app_name" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.CHECK" /&gt;
  
                  &lt;category android:name="android.intent.category.DEFAULT" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
  
          &lt;activity
              android:name="com.example.wifianalysis.wifi_on"
              android:label="@string/app_name" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.WIFION" /&gt;
  
                  &lt;category android:name="android.intent.category.DEFAULT" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
  
  
          &lt;activity
              android:name="com.example.wifianalysis.wifi_off"
              android:label="@string/app_name" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.WIFIOFF" /&gt;
  
                  &lt;category android:name="android.intent.category.DEFAULT" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
  
  
          &lt;receiver android:name=".WiFiScanReceiver"&gt;
            &lt;intent-filter&gt;
              &lt;action android:name="com.rdc" /&gt;
            &lt;/intent-filter&gt;
          &lt;/receiver&gt;
  
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>Code for my service class: </p>
  
  <p>There used to be code written here that processed information, but I decided to try the barebones of the service first to figure out what was wrong. </p>
  
     <pre class="lang-java prettyprint-override"><code>package com.example.wifianalysis;
  
      import java.util.List;
      import java.util.concurrent.ScheduledExecutorService;
  
      import android.app.Service;
      import android.content.BroadcastReceiver;
      import android.content.Context;
      import android.content.Intent;
      import android.content.IntentFilter;
      import android.net.wifi.ScanResult;
      import android.net.wifi.WifiManager;
      import android.os.Binder;
      import android.os.Handler;
      import android.os.IBinder;
      import android.widget.Toast;
  
  
      public class WifiPullService extends Service {
  
      ScheduledExecutorService scheduleTaskExecutor;
      WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
      int count =0;
      private Runnable mScanInfo;
      private final Handler mHandler = new Handler();
  
      @Override
      public IBinder onBind(Intent arg0) {
          // TODO Auto-generated method stub
          return null;
      }
  
      public class LocalBinder extends Binder {
          WifiPullService getService() {
              return WifiPullService.this;
          }
      }
  
  
  
  
  
  
  
      @Override
      public int onStartCommand(Intent intent, int flags, int startId) {
          // TODO Auto-generated method stub
  
          return super.onStartCommand(intent, flags, startId);
  
  
  
  
  
      }
  
  
  
      @Override
      public void onCreate() {
  
          super.onCreate();
          Toast.makeText(this, "Service created!", Toast.LENGTH_LONG).show();
          // TODO Auto-generated method stub
  
  
  
  
          //super.onCreate();
      }
  
      @Override
      public void onDestroy() {
          // TODO Auto-generated method stub
          Toast.makeText(this, "Service stopped", Toast.LENGTH_LONG).show();
          super.onDestroy();
      }
  
      @Override
      @Deprecated
      public void onStart(Intent intent, int startId) {
          // TODO Auto-generated method stub
          super.onStart(intent, startId);
          Toast.makeText(this, "Service started by user.", Toast.LENGTH_LONG).show();
      }
  
  
  }
  </code></pre>
  
  <p>My Main Activity:</p>
  
  <pre class="lang-java prettyprint-override"><code> package com.example.wifianalysis;
  
      import android.app.Activity;
      import android.content.Context;
      import android.content.Intent;
      import android.net.ConnectivityManager;
      import android.net.NetworkInfo;
      import android.os.Bundle;
      import android.view.Menu;
      import android.view.View;
      import android.widget.ToggleButton;
      //import android.net.wifi.WifiManager;
  
      public class MainActivity extends Activity {
  
          public void onToggleClicked(View view) { //when backbutton is pressed go back to main
              // Do something in response to button
              boolean on = ((ToggleButton) view).isChecked();
  
              try{
  
                  if (on) {
                      //Intent backIntent = new Intent("android.intent.action.CHECK");
                      Intent i = new Intent(this, WifiPullService.class);
                      startService(i); //if checked, start service
                  }
                  else{
                      stopService(new Intent(this, WifiPullService.class)); //if unchecked, stop service
                  }
              }
              catch (Exception e){
                  System.err.println("Could not start/stop service: " + e.getMessage());
              }
          }
  
  
          @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);
  
  
  
          }
  
  
          @Override
          public boolean onCreateOptionsMenu(Menu menu) {
              // Inflate the menu; this adds items to the action bar if it is present.
              getMenuInflater().inflate(R.menu.main, menu);
              return true;
          }
  </code></pre>
  
  <p>LogCat Errors:</p>
  
  <pre><code>12-06 10:38:39.440: W/dalvikvm(7458): threadid=1: thread exiting with uncaught exception (group=0x416ed450)
  
  12-06 10:38:39.460: E/AndroidRuntime(7458): FATAL EXCEPTION: main
  
  12-06 10:38:39.460: E/AndroidRuntime(7458): java.lang.RuntimeException: Unable to instantiate service com.example.wifianalysis.WifiPullService: java.lang.NullPointerException
  12-06 10:38:39.460: E/AndroidRuntime(7458): java.lang.RuntimeException: Unable to instantiate service com.example.wifianalysis.WifiPullService: java.lang.NullPointerException
  12-06 10:38:39.460: E/AndroidRuntime(7458):     at android.app.ActivityThread.handleCreateService(ActivityThread.java:2368)
  </code></pre>