I try to parsing data from my database and show it on listview. However since in logcat does't show what error volley does, I don't know how to solve it. Here's my code:
JsonResult
{"result":[{"namaBarang":"kabel","jumlahBarang":"5","tglKel":"2018-06-06"},{"namaBarang":"optical power meter","jumlahBarang":"5","tglKel":"0000-00-00"}]}
From that json result, I try to parse it with JsonObject, and here's what my JsonObject looks like.
Activity
JsonObjectRequest bkRequest=new JsonObjectRequest(Request.Method.GET, >url, null ,new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { try { JSONObject obj = response.getJSONObject("result"); BarangKeluar bk = new BarangKeluar(); bk.setNamaBarang(obj.getString("namaBarang")); bk.setJumlahBarang(obj.getString("jumlahBarang")); bk.setTglBarang(obj.getString("tglBarang")); bkList.add(bk) ; } catch (JSONException e) { e.printStackTrace(); } // notifying list adapter about data changes // so that it renders the list view with updated data adapter.notifyDataSetChanged(); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { VolleyLog.d(TAG, "Error: " + error.getMessage()); } }); // Adding request to request queue AppController.getInstance().addToRequestQueue(bkRequest);
But after I push it on my phone, the listview not populate with my json.
UPDATE1 Already trying to try pistolcaffe and IntelliJ Amiya code but still not working.
Logcat
D/TextView: setTypeface with style : 0 I/System.out: (HTTPLog)-Static: isSBSettingEnabled false I/System.out: (HTTPLog)-Static: isSBSettingEnabled false D/AbsListView: onsize change D/Volley: [1] 2.onErrorResponse: AppController
But my AppController work fine with This this tutorial.
Marked threads duplicate in Another threads. I look up on this and the difference is most of answer use HttpConnection.
Solved
Finally, I fixed this.
Here's the code after fix.
Activity
//Create JsonObjectRequest JsonObjectRequest bkRequest = new JsonObjectRequest(Request.Method.GET, url, null,new Response.Listener<JSONObject>(){ @Override public void onResponse(JSONObject response) { Log.d(TAG, response.toString()); try { JSONArray obj = response.getJSONArray("result"); for(int i=0;i< obj.length();i++) { JSONObject json = obj.getJSONObject(i); BarangKeluar bk = new BarangKeluar(); bk.setNamaBarang(json.getString("namaBarang")); bk.setJumlahBarang(json.getString("jumlahBarang")); bk.setTglBarang(json.getString("tglKel")); //Adding data into array bkList.add(bk); } } catch (JSONException e) { e.printStackTrace(); e.getMessage(); } // notifying list adapter about data changes // so that it renders the list view with updated data adapter.notifyDataSetChanged(); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { VolleyLog.d(TAG, "Error: " + error.getMessage()); } }); // Adding request to request queue AppController.getInstance().addToRequestQueue(bkRequest);