title: NullPointerException on Custom Volley Request
body: <p>i am trying to implement volley into my app using a custom request but i keep getting this error that i cant fix.</p>
  
  <p>Here is the error</p>
  
  <pre><code>java.lang.NullPointerException: Attempt to invoke virtual method 'void co.app.al.app.volley.AppController.addToRequestQueue(com.android.volley.Request, java.lang.String)' on a null object reference
  </code></pre>
  
  <p>Here is the AppController.java</p>
  
  <pre><code>public class AppController extends Application {
  
      public static final String TAG = AppController.class.getSimpleName();
  
      private RequestQueue mRequestQueue;
      private ImageLoader mImageLoader;
      LruBitmapCache mLruBitmapCache;
  
      private static AppController mInstance;
  
      @Override
      public void onCreate() {
          super.onCreate();
          mInstance = this;
      }
  
      public static synchronized AppController getInstance() {
          return mInstance;
      }
  
      public RequestQueue getRequestQueue() {
          if (mRequestQueue == null) {
              mRequestQueue = Volley.newRequestQueue(getApplicationContext());
          }
  
          return mRequestQueue;
      }
  
      public ImageLoader getImageLoader() {
          getRequestQueue();
          if (mImageLoader == null) {
              getLruBitmapCache();
              mImageLoader = new ImageLoader(this.mRequestQueue, mLruBitmapCache);
          }
  
          return this.mImageLoader;
      }
  
      public LruBitmapCache getLruBitmapCache() {
          if (mLruBitmapCache == null)
              mLruBitmapCache = new LruBitmapCache();
          return this.mLruBitmapCache;
      }
  
      public &lt;T&gt; void addToRequestQueue(Request&lt;T&gt; req, String tag) {
          req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
          getRequestQueue().add(req);
      }
  
      public &lt;T&gt; void addToRequestQueue(Request&lt;T&gt; req) {
          req.setTag(TAG);
          getRequestQueue().add(req);
      }
  
      public void cancelPendingRequests(Object tag) {
          if (mRequestQueue != null) {
              mRequestQueue.cancelAll(tag);
          }
      }
  }
  </code></pre>
  
  <p>Here is the custom request</p>
  
  <pre><code>CustomRequest jsObjRequest = new CustomRequest(Request.Method.POST,
                              jsonUrl,paramsLogin,
                              new Response.Listener&lt;JSONObject&gt;() {
                                  @Override
                                  public void onResponse(JSONObject response) {
                                      try {
                                          VolleyLog.v("Response:%n %s", response.toString(4));
                                          int code = response.getInt("code");
                                          String message = response.getString("message");
  
  
  
  
  
                                          if (code == 1) {
                                              //Success go to verify
                                              Toast.makeText(getActivity().getApplicationContext(),
                                                      message,
                                                      Toast.LENGTH_LONG).show();
                                              Log.v(TAG, String.valueOf(code));
                                              Log.v(TAG, message);
  //asd
                                          } else if (code == 2){
  
                                              int newId = response.getInt("uid");
                                              String returnDeviceToken = response.getString("device_token");
  
                                              Toast.makeText(getActivity().getApplicationContext(),
                                                      message,
                                                      Toast.LENGTH_LONG).show();
  
                                              Log.v(TAG, String.valueOf(newId));
  
  
                                              //Create the new login credentials for the user and save them to the shared preferences
                                              session.createLoginSession(newId, returnDeviceToken);
  
                                              //Send the user to the home page
                                              String mainMessage = "home";
                                              ((IndexUserActionActivity)getActivity()).startMainActivity(mainMessage);
  
  
  
                                          }else{
                                              Toast.makeText(getActivity().getApplicationContext(),
                                                      "Network Error",
                                                      Toast.LENGTH_LONG).show();
  
                                          }
                                      } catch (JSONException e) {
                                          e.printStackTrace();
                                      }
                                  }
                              }, new Response.ErrorListener() {
                          @Override
                          public void onErrorResponse(VolleyError error) {
                              VolleyLog.e("Error: ", error.getMessage());
                          }
                      });
  
                      //requestQueue.add(jsObjRequest);
  
                      AppController.getInstance().addToRequestQueue(jsObjRequest, tag_json_obj);
  </code></pre>
  
  <p>The odd thing is that this exact same code works fine on another app i am making so i cant see whats going wrong</p>
  
  <p>Thanks for any help</p>