1

I'm getting a valid JSON response from server

{
"id": "3456789912",
"desa": "Lilangan",
"kecamatan": "Gantung"
}

I want to show json object result in text view, when I click the button to run, but the text view stays empty.

Here java method to parse JSON:

private void jsonParse() {
    String userID  = noResi.getText().toString();
    String url= "http://192.168.1.123/api/json.php?id="+userID; 

    JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
            new Response.Listener<JSONObject>(){
        public void onResponse(JSONObject response){

            try {
                String desa = response.getString("desa");
                String kec = response.getString("kecamatan");
                
                tvKeterangan.append("Desa "+desa+"\nKecamatan "+kec); //This is text view to show the result
                
            } catch (JSONException e) {
                e.printStackTrace();
            }

        }
            }, Throwable::printStackTrace);
    mQueue.add(request);

}

Exception:

java.io.IOException: Cleartext HTTP traffic not permitted

Vadik Sirekanyan
  • 3,332
  • 1
  • 22
  • 29
Alam
  • 11
  • 3
  • The code you provided looks good. Are there any errors in logcat? – Vadik Sirekanyan Aug 19 '21 at 03:44
  • 1
    logcat errors: java.io.ioexception:cleartext http traffic not permitted OK now problem solved by following this method [link](https://stackoverflow.com/questions/45940861/android-8-cleartext-http-traffic-not-permitted) – Alam Aug 19 '21 at 04:32

0 Answers0