android connect to PC's localhost when debugger on mobile device-ThrowExceptions

Exception or error:

I want to debug my android application, I connect the android device to my PC using the USB cable. In my application there is a button to connect with localhost, ip for localhost is and the port is 8080, I have read that when debugging on mobile, the ip is the localhost for android device and not for my PC, so what changes should I make to the ip instead of or do I have to make another change?
In this case my android device is sony ericsson xperia arc s.

How to solve:

As is your system (pc)’s local host address (from emulator only). Actually android doesn’t recognized localhost in url. so is for that meant. Also for android device loopback address is

Your url with is correct. Also you can use Static IP of your system.

Just check for

<uses-permission android:name="android.permission.INTERNET"></uses-permission>

in your application’s manifest file.


Here you are using port 8080 so, try with adb command on your host machine.

adb forward tcp:8080 tcp:8080

Also please elaborate on this line “i want to debugger my application on my mobile”.


If you are going to test on real device use your Network IP of system (PC).


Google has added support in Chrome 29 and higher to use reverse port forwarding to access a website hosted on your local development machine through the USB cable on Chrome for Android. Setup instructions can be found at the following URL:

As of desktop Chrome 30 Reverse Port Forwarding is no longer an experimental feature in Chrome. It can be accessed by typing about:inspect in the address bar of your PC, and by clicking the “Enable port forwarding” check box and clicking the “Configure port forwarding” button located to the top right of the window.

Once that is done, connect your mobile device via USB. Open Chrome on your mobile device to localhost:8000 (or whichever port you have configured on your local server).

The Reverse Port Forwarding functionality will make sure that your Android device now sees your PC’s localhost.


For that you need to make some changes in your xampp server… Assign 1 static IP address to your system and then you need to put your xampp server in online mode. after that you can use that ip address in your android application instead of Works fine for me as i am using my localhost with my android application.


You can share your Mac’s Internet connection over Wi-Fi. Then your Android app can connect to a Servlet running on the Mac with HTTP over Wi-Fi. The steps are:

  1. Run System Preference on Mac
  2. Goto “Sharing” tab
  3. Turn on “Internet Sharing”
  4. Select “Ethernet” in the “Share your connection from” combo
  5. Select “Wi-Fi” in the “To Computers Using” list box
  6. Use “Wi-Fi Options…” button to configure Wi-Fi security. Now your Mac is a Wi-Fi server, and it is sharing its Ethernet Internet connection.
  7. Configure your Android device’s Wi-Fi to connect to your Mac (in Settings command)
  8. On your Mac, goto the Network tab in System Preferences, and select Wi-Fi in list to find out the IP address of your Mac on the Wi-Fi network (for me it was
  9. In your Android App you can now connect to the Servlet in your Mac with “”


I think you have two options

The first one is using when you use your real android works for me.

Your Second opt is creating hotspot from your pc and connect your android device to the hotspot.

Find the ip address using cmd type “ipconfig” replace localhost with the ip address.


Leave a Reply

Your email address will not be published. Required fields are marked *