-1

i have a django server but the app crash in the android emulator, why?

it is the code:

final TextView t = findViewById(R.id.textView3);
    RequestQueue queue = Volley.newRequestQueue(this);
    String url = "http://10.0.2.2:8000/";
    StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    // Display the first 500 characters of the response string.
                    t.setText("Response is: "+ response.substring(0,500));
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            t.setText("That didn't work!");
        }
    });
  • Please post the logcat. You need to tell the exception that is thrown and not catched. And which statement causes the crash. – greenapps May 31 '18 at 10:54

3 Answers3

0

If the server is running on localhost and app on emulator, then you have to give the other IP as BaseUrl in app.

steps: -> Open terminal, and type ifconfig(on mac os) -> Copy the inet IP address which is shown in en0, and set that as BaseUrl in the app

Keshav Aggarwal
  • 754
  • 6
  • 14
0

Possible duplicate How do you connect localhost in the Android emulator?

In case Genymotion then try 10.0.3.2

Sajjad
  • 500
  • 4
  • 7
0

Use your computers actual IP address! replace 10.0.2.2 with your systems actual IP,check java.net.ConnectException: failed to connect to /10.0.0.2 (port 80): connect failed: ETIMEDOUT (Connection timed out)

Hilary Mwape
  • 425
  • 1
  • 4
  • 15