I'm quite new to Java/Android Studio and am spending the past two days figuring this out, without succes. I keep getting: Cannot resolve constructor 'JsonArrayRequest(int, java.lang.String, java.lang.String, anonymous com.android.volley.Response.Listener)'
On other threads I see answers that suggest to replace the null to a string or cast the null but this doesn't seem to make the trick.
I'm trying to read the JSON Array at https://www.smartvibes.be/profiles/api/profileview.php?id=5073 for instance.
This is my code:
package com.smartvibes.smartbeat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.toolbox.JsonArrayRequest;
import com.android.volley.toolbox.Volley;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class profileViewActivity extends AppCompatActivity {
RequestQueue rs;
String url,id, nick, age, city, mainpic, numpics, extrapic0, extrapic1, extrapic2, extrapic3, extrapic4, extrapic5;
TextView profileIntro;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile_view);
Bundle getProfileId = getIntent().getExtras();
if(getProfileId == null){
return;
}
String profileid = getProfileId.getString("profileid");
url = "https://www.smartvibes.be/profiles/api/profileview.php?id="+profileid;
rs = Volley.newRequestQueue(this);
sendjsonrequest();
profileIntro = (TextView) findViewById(R.id.profileIntro);
//profileIntro.setText(profileData.getPnick());
profileIntro.setText(profileid);
}
public void sendjsonrequest(){
JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.GET, url, "", new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
try {
// Get current json Array
JSONArray profile = new JSONArray(response);
JSONObject jresponse = profile.getJSONObject(0);
Toast.makeText(profileViewActivity.this, "test", Toast.LENGTH_LONG).show();
nick = jresponse.getString("nick");
age = jresponse.getString("age");
city = jresponse.getString("city");
mainpic = jresponse.getString("mainpic");
numpics = jresponse.getString("numpics");
} catch (JSONException e) {
e.printStackTrace();
}
}
});
rs.add(jsonArrayRequest);
}
}
When trying to run it I get:
error: no suitable constructor found for JsonArrayRequest(int,String,String,<anonymous Listener<JSONArray>>)
constructor JsonArrayRequest.JsonArrayRequest(String,Listener<JSONArray>,ErrorListener) is not applicable
(actual and formal argument lists differ in length)
constructor JsonArrayRequest.JsonArrayRequest(int,String,JSONArray,Listener<JSONArray>,ErrorListener) is not applicable
(actual and formal argument lists differ in length)
I'm probably doing something (or several things) bad... But can't figure out what.