I am working with an application that must connect with web services to be able to consult information from a remote DB, but when I press a button to launch my web service it gives me the following error:
Attempt to invoke virtual method 'com.android.volley.Request com.android.volley.RequestQueue.add (com.android.volley.Request) 'on a null object reference
I do not know why it gives this error, when my application starts loading a web service that starts without problems but when using the button to launch the next web service it is where it marks the error, this is the class where I am connecting with my Base of data:
public class noticiasWebService implements Response.Listener<JSONObject>, Response.ErrorListener {
RequestQueue request;
JsonObjectRequest jsonObjectRequest;
public void update(String tituloNoticia, String subtituloNoticia, String imagenNoticia, String descripcionNoticia) {
String url = "http://192.168.1.72:80/webservicemgrex/agregarFavoritos.php?tituloFavorito="+tituloNoticia+"" +
"&subtituloFavorito="+subtituloNoticia+
"&imagenFavorito="+imagenNoticia+
"&descripcionFavoritos="+descripcionNoticia;
url = url.replace(" ","%20");
jsonObjectRequest = new JsonObjectRequest(Request.Method.GET,url,null,this,this);
request.add(jsonObjectRequest);
}
@Override
public void onResponse(JSONObject response) {
Log.i("Error","Se haregistrado con exito: "+response);
}
@Override
public void onErrorResponse(VolleyError error) {
Log.i("Error","No se pudo consultar el registro: "+error.toString());
}
}