1

I am beginner to android. I am now currently doing my school project in which I retrieve the JSON data from localserver into recyclerview.

When I run the app on the Emulator, it works. But when I try to run it on my real device, there is an error to connect with JSON files and I cannot even connect to my JSON files. Though my laptop and my phone are also in the same network, I cannot connect with the JSON files.

I was searching for this error anywhere, but I cannot find it.

Here is my error logcat.

11-20 14:57:00.609 9832-11323/com.example.kyaw_thit.live_animation E/Volley: 
[5754] BasicNetwork.performRequest: Unexpected response code 403 for 
http://132.1.4.174/Travel/home/home.json
11-20 14:57:00.609 9832-9832/com.example.kyaw_thit.live_animation 
V/MediaPlayer: disconnect
11-20 14:57:00.616 9832-9832/com.example.kyaw_thit.live_animation 
I/System.out:  ERROR  :  com.android.volley.AuthFailureError

This is my codes to retrieve the JSON data.

   private String url_home = "http://132.1.4.174/Travel/home/home.json";
   public void getHome(){

    JsonArrayRequest home_req = new JsonArrayRequest(url_home,
            new Response.Listener<JSONArray>() {
                @Override
                public void onResponse(JSONArray response) {
                    for (int i = 0; i < response.length(); i++) {
                        try {
                            Log.d(TAG,"response " + response);

                            JSONObject home_obj = response.getJSONObject(i);
                            Home_Model home_model = new Home_Model();
                            home_model.setHome_name(home_obj.getString("name"));
                            home_model.setUrl_home(home_obj.getString("image"));
                            home_model.setId(home_obj.getInt("id"));
                            hList.add(home_model);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                    hAdapter.notifyDataSetChanged();
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            System.out.println(" ERROR  :  " +error.toString());
        }
    });

    AppController.getInstance().addToRequestQueue(home_req);

}

This is where I stored my JSON files. C:\wamp64\www\Travel\home

May I know how can I solve this? Or is there another ways to deal with JSON files besides using local server.

Help me please! I would appreciate any help. Thanks.

kyt23
  • 23
  • 5
  • don't you need to use device ip address as to host as you are using local server ? – hemen Nov 20 '17 at 08:18
  • I tried bro, but still can't connect. My logcat shows ` com.android.volley.NoConnectionError: java.net.ConnectException: Connection refused` @Cyborg91 – kyt23 Nov 20 '17 at 08:33

0 Answers0