title: Android Volley synchronous request not working
body: <p>I am trying to make a <strong>synchronous request</strong> to the server using <strong>RequestFuture</strong> but it's not working . The same request when done using asynchronous works fine.</p>
  
  <p>This is my code:</p>
  
  <pre><code> public void fetchModules(){
     JSONObject response = null;
      RequestQueue requestQueue = Volley.newRequestQueue(getContext());
  
      RequestFuture&lt;JSONObject&gt; future = RequestFuture.newFuture();
      JsonObjectRequest request = new JsonObjectRequest(Url.ALL_MODULES_URL,null,future,future);
      requestQueue.add(request);
  
  
      try {
           response = future.get(3, TimeUnit.SECONDS); // Blocks for at most 10 seconds.
      } catch (InterruptedException e) {
               Log.d(TAG,"interupted");
       } catch (ExecutionException e) {
          Log.d(TAG,"execution");
      } catch (TimeoutException e) {
          e.printStackTrace();
      }
  
      Log.d(TAG,response.toString());
  }
  </code></pre>
  
  <p>I am getting a nullpointerexception:</p>
  
  <blockquote>
    <p>java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String org.json.JSONObject.toString()' on a null object reference
                                                                       at com.maths.app.AllModules.fetchModules(AllModules.java:85)
                                                                       at com.maths.app.AllModules.onCreateView(AllModules.java:51)
                                                                       at android.support.v4.app.Fragment.performCreateView(Fragment.java:2080)
                                                                       at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1108)
                                                                       at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1290)
                                                                       at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:801)
                                                                       at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1677)
                                                                       at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:536)
                                                                       at android.os.Handler.handleCallback(Handler.java:746)
                                                                       at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                       at android.os.Looper.loop(Looper.java:148)
                                                                       at android.app.ActivityThread.main(ActivityThread.java:5443)
                                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
                                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)</p>
  </blockquote>
  
  <p>it's returning a null response. How can I solve this?</p>