The RequestQueue returns null

0

Well I have a code on Android that should be connected to a Web Service, but I can not connect and the truth is that I do not know why. I have started the RequestQueue requestqueue=Volley.newRequestQueue(this); but it gives me null and I drop the application when I get to that line.

Here is my code:

public class ConnectionHTTP extends AppCompatActivity implements com.android.volley.Response.Listener<JSONObject>, com.android.volley.Response.ErrorListener
{

    RequestQueue rq;
    JsonRequest jrq;
    StringRequest strq;
    Context c;
    boolean replay;
    public ConnectionHTTP(Context c){
        this.c=c;

    }

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


    }

public boolean startSession(final String user, final String password){

    final String file="/login/session.php";
    final String url=ip+file;
    rq=Volley.newRequestQueue(c.getApplicationContext());

    strq=new StringRequest(Request.Method.POST, url, new com.android.volley.Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            if(response.trim().equals("success"))
                replay=true;
        }
        }
    , new com.android.volley.Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
        replay=false;
        }
    }){
      protected  Map<String,String>getParams() throws AuthFailureError{
          Map<String,String>params=new HashMap<>();
          params.put("u_name",user.trim());
          params.put("pass",password.trim());
          return  super.getParams();
      }
    };

    rq.add(strq);
    return replay;
    }


}

Activity calling the method StartSession(String,String) :

public class SingIn_Activity extends AppCompatActivity  {
    EditText user,pass;
    ConnectionDB con;

    Button login,reg;

    Connection connect;
    String User,Pass;
    ProgressBar circular;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_log);

        user=(EditText)findViewById(R.id.usertext);
        pass=(EditText) findViewById(R.id.passtext);
        circular=(ProgressBar)findViewById(R.id.progressBar3);


    }



    //Connect to SQL
    public int login(Context c,String user,String password)  {
        boolean flag;
        int isExist=0;
        ConnectionHTTP msql = new ConnectionHTTP(this);
        flag=msql.startSession(user,password);
        if(flag){
            isExist=1;
        }
return isExist;
}

And this is my catlog :

   --------- beginning of crash
2018-11-10 10:00:49.641 1776-1776/com.example.julio.photogo E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.julio.photogo, PID: 1776
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.julio.photogo/com.example.julio.photogo.Main_Activity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.content.Context.getApplicationContext()' on a null object reference
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6541)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.content.Context.getApplicationContext()' on a null object reference
        at android.content.ContextWrapper.getApplicationContext(ContextWrapper.java:109)
        at com.example.julio.photogo.ConnectionHTTP.startSession(ConnectionHTTP.java:44)
        at com.example.julio.photogo.SingIn_Activity.login(SingIn_Activity.java:47)
        at com.example.julio.photogo.Main_Activity.SESSION(Main_Activity.java:58)
        at com.example.julio.photogo.Main_Activity.onCreate(Main_Activity.java:46)
        at android.app.Activity.performCreate(Activity.java:6975)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) 
        at android.app.ActivityThread.-wrap11(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593) 
        at android.os.Handler.dispatchMessage(Handler.java:105) 
        at android.os.Looper.loop(Looper.java:164) 
        at android.app.ActivityThread.main(ActivityThread.java:6541) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 
2018-11-10 10:00:49.648 1776-1776/com.example.julio.photogo E/UncaughtException: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.julio.photogo/com.example.julio.photogo.Main_Activity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.content.Context.getApplicationContext()' on a null object reference
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6541)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.content.Context.getApplicationContext()' on a null object reference
        at android.content.ContextWrapper.getApplicationContext(ContextWrapper.java:109)
        at com.example.julio.photogo.ConnectionHTTP.startSession(ConnectionHTTP.java:44)
        at com.example.julio.photogo.SingIn_Activity.login(SingIn_Activity.java:47)
        at com.example.julio.photogo.Main_Activity.SESSION(Main_Activity.java:58)
        at com.example.julio.photogo.Main_Activity.onCreate(Main_Activity.java:46)
        at android.app.Activity.performCreate(Activity.java:6975)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) 
        at android.app.ActivityThread.-wrap11(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593) 
        at android.os.Handler.dispatchMessage(Handler.java:105) 
        at android.os.Looper.loop(Looper.java:164) 
        at android.app.ActivityThread.main(ActivityThread.java:6541) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 
    
asked by Julio Mizrahi 10.11.2018 в 00:56
source

0 answers