title: Android create simple volley Singleton class to prepare GET and POST method
body: <p>with android <code>Volley</code> tutorials i'm creating simple single Singleton class as an Volley, but after prepare GET and POST method i get <code>NullPointerException</code> error and i can not find whats error:</p>
  
  <p>AppControllert <code>Volley</code> singleton class:</p>
  
  <pre><code>public class ApplicationController extends Application {
      public static final String TAG = "VolleyPatterns";
      private RequestQueue mRequestQueue;
      private static ApplicationController sInstance;
  
      @Override
      public void onCreate() {
          super.onCreate();
          sInstance = this;
      }
      public static synchronized ApplicationController getInstance() {
          return sInstance;
      }
      public RequestQueue getRequestQueue() {
          if (mRequestQueue == null) {
              mRequestQueue = Volley.newRequestQueue(getApplicationContext());
          }
          return mRequestQueue;
      }
      public &lt;T&gt; void addToRequestQueue(Request&lt;T&gt; req, String tag) {
          req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
          VolleyLog.e("Adding request to queue: %s", req.getUrl());
          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>and in Activity i'm try to create simple request with this class:</p>
  
  <pre><code>final String URL = "http://192.168.1.6/apitest";
  JsonObjectRequest req = new JsonObjectRequest(URL, null,
          new Response.Listener&lt;JSONObject&gt;() {
              @Override
              public void onResponse(JSONObject response) {
                  Log.e("Response:", response.toString());
              }
          }, new Response.ErrorListener() {
      @Override
      public void onErrorResponse(VolleyError error) {
          Log.e("Error: ", error.getMessage());
      }
  });
  ApplicationController.getInstance().addToRequestQueue(req);
  </code></pre>
  
  <p>Logcat error:</p>
  
  <pre><code>Caused by: java.lang.NullPointerException
              at asrebidaree.ir.asrebidaree.ActivityRegistration.onCreate(ActivityRegistration.java:37)
  </code></pre>
  
  <p>Line 37 is : <code>ApplicationController.getInstance().addToRequestQueue(req);</code></p>