Error de compilación al utilizar JsonObjectRequest
Estoy usando mcxiaoke / android-volley library.Im obtener error de compilación como
Error:(77, 37) error: reference to JsonObjectRequest is ambiguous, both constructor JsonObjectRequest(int,String,String,Listener<JSONObject>,ErrorListener) in JsonObjectRequest and constructor JsonObjectRequest(int,String,JSONObject,Listener<JSONObject>,ErrorListener) in JsonObjectRequest match
Este es mi código. No sé lo que está mal. Cualquier ayuda apreciada
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, getRequestUrl(10), null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { } });
Cast el null a cadena o JSONObject y debería funcionar bien creo.
new JsonObjectRequest(Request.Method.GET, getRequestUrl(10), (String)null, new Response.Listener<JSONObject>()
Bill Gates tiene razón, no hay forma de que la clase sepa qué constructor utilizar si pasa en null en lugar del objeto de tipo String o JSONObject que está esperando en uno de los constructores de lo contrario obtendrá este error ambiguo, diciendo que El constructor tiene 2 coincidencias.
Tratar:
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, getRequestUrl(10), "", new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { } });
Usted acaba de utilizar referencia nula.
new JsonObjectRequest(Request.Method.GET, getRequestUrl(10), (String)null, new Response.Listener<JSONObject>()
Su trabajo para mi