0
votes

Here is the error message:

Error:(56, 42) error: reference to JsonObjectRequest is ambiguous both constructor JsonObjectRequest(int,String,String,Listener,ErrorListener) in JsonObjectRequest and constructor JsonObjectRequest(int,String,JSONObject,Listener,ErrorListener) in JsonObjectRequest match

Look up the attached picture:

enter image description here

1
since your sending null it can be String or JSONObject so the compiler cant decide which constractor to call.. - Itzik Samara
I dont understand it runs on my friends computer but I get the error on my could it be android studio ? - aasim ali

1 Answers

0
votes

There are two similar constructors for com.android.volley.toolbox.JsonObjectRequest which have 5 parameters:

1

public JsonObjectRequest(int method, String url, String requestBody, Listener<JSONObject> listener, ErrorListener errorListener)

2

public JsonObjectRequest(int method, String url, JSONObject jsonRequest, Listener<JSONObject> listener, ErrorListener errorListener) {

If you pass null for the third parameter, it is impossible to detect which constructor you want to use. null for requestBody or null for jsonRequest?

You should better use another constructor:

public JsonObjectRequest(int method, String url, Listener<JSONObject> listener, ErrorListener errorListener)

or at your version of volley it should be:

public JsonObjectRequest(int method, String url, Listener<JSONObject> listener)

Or you can try to set third paramter;

1

with empty string (such as "") to use first constructor.

2

with empty but an instance of JSONObject (such as new JSONObject()) to use second constructor.

Edit: I guess you are using an older version of volley. At 1.0.19 version ErrorListener's are added to the constructors. So the consturctors at my answer are later version of yours. But the idea is same.