Reputation: 1
I have an issue with getting a response from Volley. I have 3 data in tables, but volley only returns 2 data. This is what I got in the browser:
And volley returns only index 0 and 1. Could anyone find out what's wrong?
Here my Volley code
val stringRequest = StringRequest(Request.Method.GET, url,
Response.Listener<String> {
response ->
Log.d("response", response)
val jsonObj = JSONObject(response)
val list = jsonObj.getJSONArray("list_pengaduan")
if(list != null){
for(i in 0 until list.length()){
val adu = Pengaduan(
list.getJSONObject(i).getInt("Id_pg"),
list.getJSONObject(i).getString("Judul"),
list.getJSONObject(i).getString("Tujuan"),
list.getJSONObject(i).getString("Prodi"),
list.getJSONObject(i).getString("Fakultas"),
list.getJSONObject(i).getString("Kategori"),
list.getJSONObject(i).getString("Image"),
list.getJSONObject(i).getString("Post"),
list.getJSONObject(i).getString("Slug"),
list.getJSONObject(i).getString("Nim"),
list.getJSONObject(i).getString("Modified"),
list.getJSONObject(i).getString("Status")
)
pengaduan.add(adu)
}
adapter.notifyDataSetChanged()
}
},
Response.ErrorListener {
error ->
Log.d("error", error.toString())})
Volley.newRequestQueue(this).add(stringRequest)
Upvotes: 0
Views: 131
Reputation: 1
Actually there is error in Volley's cache, so I need to use:
Volley.newRequestQueue(this).cache.clear()
before add a request
Upvotes: 0
Reputation: 15423
Try using
for(i in 0 .. list.length())
Instead of
for(i in 0 until list.length())
As until
exclude the last element.
Check official doc for more information.
Upvotes: 1