Http connection to your local Tomcat or Apache server not working when using the Android emulatorThis was really painful as I wasted hours figuring out why my Android emulator can't connect to 127.0.0.1 or localhost. I wrote a Servlet in Tomcat that was running on localhost port 8080 and I could get it from the Browser or Eclipse window. But when I reference that in my Android Activity it was not working.
Here is the fix:
Just switch the localhost or 127.0.0.1 to 10.0.2.2
Why we need this fix?
127.0.0.1 is the emulated system's own loopback interface, not the one running on
your host development machine. within the Android system, one should use 10.0.2.2 which is an alias specifically setup to contact your host 127.0.0.1