title: NullPointer Exception Volley android studio
body: <p>I am working in a <code>Page2</code> activity in Android Studio and I am using php file <code>pause_in</code>, below is java code using Volley class.It gives me the error:
  <code>java.lang.NullPointerException:
  Attempt to invoke virtual method 'com.android.volley.Request com.android.volley.RequestQueue.add(com.android.volley.Request)' on a null object reference</code>.
  But after I have added the line for initializing the request,it gives me that:(I have to mention that I used getExtra method to get the variables of email and password from the first screen).</p>
  
  <pre><code>12-08 12:49:03.446 1346-1370/? W/audio_hw_generic: Not supplying enough 
  data to HAL, expected position 455229 , only wrote 455040
  12-08 12:49:03.446 2245-2245/? D/key: valuee
  12-08 12:49:03.514 2245-2245/? W/System.err: org.json.JSONException: 
  End of input at character 1 of 
  12-08 12:49:03.514 2245-2245/? W/System.err:     at 
  org.json.JSONTokener.syntaxError(JSONTokener.java:449)
  12-08 12:49:03.514 2245-2245/? W/System.err:     at 
  org.json.JSONTokener.nextValue(JSONTokener.java:97)
  12-08 12:49:03.514 2245-2245/? W/System.err:     at 
  org.json.JSONObject.&lt;init&gt;(JSONObject.java:156)
  12-08 12:49:03.514 2245-2245/? W/System.err:     at 
  org.json.JSONObject.&lt;init&gt;(JSONObject.java:173)
  12-08 12:49:03.514 2245-2245/? W/System.err:     at 
  com.example.a.mysql_php_register_login.Page2$1$1.
  onResponse(Page2.java:96)
  12-08 12:49:03.514 2245-2245/? W/System.err:     at 
  com.example.a.mysql_php_register_login.Page2$1$1.
  onResponse(Page2.java:89)
  12-08 12:49:03.514 2245-2245/? W/System.err:     at 
  com.android.volley.toolbox.StringRequest.
  deliverResponse(StringRequest.java:67)
  12-08 12:49:03.514 2245-2245/? W/System.err:     at 
  
  com.android.volley.toolbox.StringRequest.
  deliverResponse(StringRequest.java:30)
  12-08 12:49:03.514 2245-2245/? W/System.err:     at 
  
     com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable
    .run(ExecutorDelivery.java:99)
    12-08 12:49:03.514 2245-2245/? W/System.err:     at 
    android.os.Handler.handleCallback(Handler.java:751)
    12-08 12:49:03.514 2245-2245/? W/System.err:     at 
    android.os.Handler.dispatchMessage(Handler.java:95)
    12-08 12:49:03.514 2245-2245/? W/System.err:     at 
    android.os.Looper.loop(Looper.java:154)
    12-08 12:49:03.514 2245-2245/? W/System.err:     at 
   android.app.ActivityThread.main(ActivityThread.java:6077)
   12-08 12:49:03.514 2245-2245/? W/System.err:     at 
   java.lang.reflect.Method.invoke(Native Method)
    12-08 12:49:03.514 2245-2245/? W/System.err:     at 
    com.android.internal.os.ZygoteInit$MethodAndArgsCaller.
    run(ZygoteInit.java:866)
    12-08 12:49:03.514 2245-2245/? W/System.err:     at 
    com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
   12-08 12:49:06.079 1586-1596/? I/ActivityManager: Killing 
   3211:com.android.gallery3d/u0a49 (adj 906): empty #17
  
  import android.content.Intent;
  import android.os.Bundle;
  import android.support.annotation.NonNull;
  import android.support.annotation.Nullable;
  import android.support.design.widget.NavigationView;
  import android.support.v4.app.FragmentTransaction;
  import android.support.v4.widget.DrawerLayout;
  import android.support.v7.app.ActionBarDrawerToggle;
  import android.support.v7.app.AppCompatActivity;
  import android.support.v7.widget.Toolbar;
  import android.util.Log;
  import android.view.MenuItem;
  import android.view.View;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.Toast;
  
  import com.android.volley.RequestQueue;
  import com.android.volley.toolbox.StringRequest;
  import com.android.volley.toolbox.Volley;
  import com.android.volley.AuthFailureError;
  import com.android.volley.Request;
  
  import com.android.volley.Response;
  import com.android.volley.VolleyError;
  import com.android.volley.toolbox.StringRequest;
  import com.android.volley.toolbox.Volley;
  
  import org.json.JSONException;
  import org.json.JSONObject;
  
  import java.util.HashMap;
  import java.util.Map;
  
  
  
  public class Page2 extends AppCompatActivity {
  
  private EditText emailI,passwordI;
  
  DrawerLayout drawerLayout;
  Toolbar toolbar;
  ActionBarDrawerToggle actionBarDrawerToggle;
  FragmentTransaction fragmentTransaction;
  NavigationView navigationView;
  
  Button pauseIn;
  EditText pause;
  
  
  private RequestQueue requestQueue;
  private static final String URL = "http://10.31.16.22/pause_in.php";
  private StringRequest request;
  
  
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.page2_activity);
  
  
  
      emailI=(EditText)findViewById(R.id.emailiImprovizum);
      passwordI=(EditText)findViewById(R.id.passImprovizum);
  
  
  
  
  
      pauseIn = (Button) findViewById(R.id.btnPauseIn);
      pauseIn.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
  
              request = new StringRequest(Request.Method.POST, URL, new 
      Response.Listener&lt;String&gt;() {
                  @Override
                  public void onResponse(String response) {
                      try {
                           JSONObject jsonObject = new 
       JSONObject(response);
                          if 
       (jsonObject.names().get(0).equals("success1")) {
                            //  Log.d("dfr","a po bon");
                              Toast.makeText(getApplicationContext(), 
        "SUCCESS " + jsonObject.getString("success1"), 
        Toast.LENGTH_SHORT).show();
  
  
  
  
                              Intent intent = getIntent();
                              String e = intent.getStringExtra("Email");
                              String p = 
         intent.getStringExtra("Password");
  
                              emailI.setText(e);
                              passwordI.setText(p);
  
                              startActivity(new 
          Intent(getApplicationContext(), about.class));
  
  
                          } else if 
         (jsonObject.names().get(0).equals("fail1")) {
                              Toast.makeText(getApplicationContext(), 
       "Error" + jsonObject.getString("fail1"), 
       Toast.LENGTH_SHORT).show();
                          }
  
  
                      } catch (JSONException e) {
                          e.printStackTrace();
                      }
  
  
                  }
              }, new Response.ErrorListener() {
                  @Override
                  public void onErrorResponse(VolleyError error) {
  
  
                  }
              }){
                  @Override
                  protected Map&lt;String, String&gt; getParams() throws 
           AuthFailureError {
                      HashMap&lt;String,String&gt; hashMap = new 
            HashMap&lt;String, String&gt;();
                      hashMap.put("pause_in","pauseIn");
  
                      hashMap.put("emailI",emailI.getText().ToString());
  
                 hashMap.put("passwordI",password.getText().ToString());
  
  
  
                      return hashMap;
                  }
              };
  
              requestQueue.add(request);
              Log.d("key","valuee");
          }
      });
  
      toolbar = (Toolbar) findViewById(R.id.toolbar);
      setSupportActionBar(toolbar);
  
      drawerLayout = (DrawerLayout) findViewById(R.id.drawableT);
      actionBarDrawerToggle = new ActionBarDrawerToggle(this, 
      drawerLayout, toolbar,
              R.string.drawer_open, R.string.drawer_close);
  
  
  
  
  
  
  
  
  actionBarDrawerToggle.getDrawerArrowDrawable().setColor(getResources()
  .getColor(R.color.white));
  
      drawerLayout.addDrawerListener(actionBarDrawerToggle);
  
      fragmentTransaction = 
   getSupportFragmentManager().beginTransaction();
  
      fragmentTransaction.commit();
  
      navigationView = (NavigationView) 
  findViewById(R.id.navigation_view);
      navigationView.setNavigationItemSelectedListener(new 
   NavigationView.OnNavigationItemSelectedListener() {
          @Override
          public boolean onNavigationItemSelected(@NonNull MenuItem item) 
    {
  
              switch (item.getItemId()) {
  
                  case R.id.about_id:
                      Intent i = new Intent(Page2.this, about.class);
                      startActivity(i);
  
                      break;
  
  
                  case R.id.id_instructions:
  
                      Intent i3 = new Intent(Page2.this, about.class);
                      startActivity(i3);
  
                      break;
              }
  
              return false;
          }
      });
  
  
  }
  
  @Override
  protected void onPostCreate(@Nullable Bundle savedInstanceState) {
      super.onPostCreate(savedInstanceState);
      actionBarDrawerToggle.syncState();
      }
  }
  
  
  &lt;?php
  include_once 'connection.php';
  
  
  
  
  class User1{
  
  private $db;
  private $connection;
  
  function __construct() {
          $this -&gt; db = new DB_Connection();
          $this -&gt; connection = $this-&gt;db-&gt;getConnection();
      }
  
  public function pause($email,$password)
      {
          $pauseIn=time();
          $query = "Select * from users where email='$email' and password 
       ='$password'";
  
          $result = mysqli_query($this-&gt;connection, $query);
          if(mysqli_num_rows($result)&gt;0){
          $query2="update users set pause_in='$pauseIn' where 
        email='$email' ";
          $inserted = mysqli_query($this -&gt; connection, $query2);
          if($inserted ==1 )
          {
              $json['success1'] = 'welcome';
              echo json_encode($json);
              mysqli_close($this -&gt; connection);
          }
          else{
  
                  $json['fail1'] = ': Email or password is wrong';
  
              echo json_encode($json);
  
          }
  
               }
  
  
          }
     }
     $user = new User1();
  
  
  
     if(isset($_POST['email'],$_POST['password'])) {
      $email=$_POST['email'];
      $password=$_POST['password'];
  
      $user-&gt; pause($email,$password);
  
          }
          else{
  
          }
      ?&gt;
  </code></pre>