title: Android service always null
body: <p>I'm trying to start a service, but always getting NPE. What could I be doing wrong?
  Even the <code>onServiceConnected()</code> method does not get called, why ever?</p>
  
  <pre><code>    @Override
      protected void onCreate(Bundle savedInstanceState) {
         mServiceIntent = new Intent(this, MyService.class);
         bindService(mServiceIntent, mConnection, Context.BIND_AUTO_CREATE);
         //other stuff
      }
  </code></pre>
  
  <p>usage:</p>
  
  <pre><code>private okButton(View v) {
      startService(mServiceIntent);
  }
  </code></pre>
  
  <p>result: NullPointerException!</p>
  
  <pre><code>private ServiceConnection mConnection = new ServiceConnection() {
            @Override
            public void onServiceConnected(ComponentName className, IBinder service) {
                 Log.v("service", "gets never executed!");
                 mDownloadService = ((LocalBinder&lt;MyService&gt;) service).getService();
              }
  
          @Override
              public void onServiceDisconnected(ComponentName className) {
              }
          };
  }
  
  public class LocalBinder&lt;S&gt; extends Binder {
      private String TAG = "LocalBinder";
      private  WeakReference&lt;S&gt; mService;
  
  
      public LocalBinder(S service){
          mService = new WeakReference&lt;S&gt;(service);
      }
  
  
      public S getService() {
          return mService.get();
      }
  }
  </code></pre>
  
  <p>Of course I also have the service in manifest:</p>
  
  <pre><code>&lt;service android:enabled="true" android:name=".service.MyService" /&gt;
  </code></pre>
  
  <p>Logcat:</p>
  
  <pre><code>06-06 23:48:20.411: W/dalvikvm(592): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
  06-06 23:48:20.461: E/AndroidRuntime(592): FATAL EXCEPTION: main
  06-06 23:48:20.461: E/AndroidRuntime(592): java.lang.RuntimeException: Unable to start activity ComponentInfo{MyActivity}: java.lang.NullPointerException
  06-06 23:48:20.461: E/AndroidRuntime(592):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
  06-06 23:48:20.461: E/AndroidRuntime(592):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
  06-06 23:48:20.461: E/AndroidRuntime(592):  at android.app.ActivityThread.access$600(ActivityThread.java:123)
  06-06 23:48:20.461: E/AndroidRuntime(592):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
  06-06 23:48:20.461: E/AndroidRuntime(592):  at android.os.Handler.dispatchMessage(Handler.java:99)
  06-06 23:48:20.461: E/AndroidRuntime(592):  at android.os.Looper.loop(Looper.java:137)
  06-06 23:48:20.461: E/AndroidRuntime(592):  at android.app.ActivityThread.main(ActivityThread.java:4424)
  06-06 23:48:20.461: E/AndroidRuntime(592):  at java.lang.reflect.Method.invokeNative(Native Method)
  06-06 23:48:20.461: E/AndroidRuntime(592):  at java.lang.reflect.Method.invoke(Method.java:511)
  06-06 23:48:20.461: E/AndroidRuntime(592):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
  06-06 23:48:20.461: E/AndroidRuntime(592):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
  06-06 23:48:20.461: E/AndroidRuntime(592):  at dalvik.system.NativeStart.main(Native Method)
  06-06 23:48:20.461: E/AndroidRuntime(592): Caused by: java.lang.NullPointerException
  06-06 23:48:20.461: E/AndroidRuntime(592):  at MyActivity.okButton(MyActivity.java:217)
  06-06 23:48:20.461: E/AndroidRuntime(592):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1939)
  06-06 23:48:20.461: E/AndroidRuntime(592):  ... 11 more
  </code></pre>
  
  <p>The intent seems to be ok:</p>
  
  <pre><code>Log.v("service", String.valueOf(mServiceIntent == null)); //false
  </code></pre>