title: How to use volley in Service class?
body: <p>I am trying to send request to a url and on successful response return a boolean value. What I am doing wrong ? As soon as I install the application <code>NullPointerException</code> is encountered at following line.</p>
  
  <p>/*    <code>private final RequestQueue   reQueue=Volley.newRequestQueue(this);</code> */</p>
  
  <pre><code>package com.exampfle.real;
  
  import com.android.volley.RequestQueue;
  import com.android.volley.Response;
  import com.android.volley.VolleyError;
  import com.android.volley.toolbox.StringRequest;
  import com.android.volley.toolbox.Volley;
  
  import android.app.AlertDialog;
  import android.app.Service;
  import android.content.Context;
  import android.content.Intent;
  import android.os.Binder;
  import android.os.IBinder;
  import android.util.Log;
  
  public class RealService extends Service{
  
      private static final String TAG="RealService";
      private boolean isRunning=false;
      private IBinder mBinder=new MyBinder();
      private boolean intenetAccess=false;
  /* Geting NullPointerException at following line */
      private final RequestQueue   reQueue=Volley.newRequestQueue(this);
      private final String url="http://www.google.com";
  
      public boolean SendRequest()
      {
          StringRequest request=new StringRequest(com.android.volley.Request.Method.GET,
                  url, 
                  new Response.Listener&lt;String&gt;() {
  
              @Override
              public void onResponse(
                      String response) {
  
                  intenetAccess=true;
              }
          },
  
          new Response.ErrorListener() {
  
              @Override
              public void onErrorResponse(
                      VolleyError error) {
  
                  intenetAccess=false;
  
              }
          });
  
          try{
              reQueue.add(request);
          }
          catch(Exception e){}
  
          return intenetAccess;
  
      }
  
      @Override
      public void onCreate() {
          super.onCreate();
          Log.i(TAG, "Service onCreate");
  
          isRunning=true;
  
      }
  
  
  
      @Override
      public IBinder onBind(Intent intent) {
          Log.i(TAG, "Service onBind");
          return mBinder;
      }
  
      @Override
      public void onRebind(Intent intent) {
          Log.i(TAG, "Service onRebind");
          super.onRebind(intent);
      }
  
      @Override
      public boolean onUnbind(Intent intent) {
          Log.i(TAG, "Service onUnBind");
          return true;
      }
  
      @Override
      public void onDestroy() {
  
      isRunning=false;
  
          Log.i(TAG, "Service onDestroy");
          super.onDestroy();
      }
  
  
  
      public class MyBinder extends Binder
      {
          RealService getService()
          {
              return RealService.this;
          }
      }
  }
  </code></pre>