Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.net.ConnectException: localhost/127.0.0.1:8080 - Connection refused

Tags:

android

I am using xampp apache server to serve resources to the application from my machine. But i am getting the above error.

I got something on the google. pointing towards possible solution here http://groups.google.com/group/android-beginners/browse_thread/thread/599a06416fb37b4a

What is the solution for the above problem?

like image 951
pradeep Avatar asked Mar 31 '11 05:03

pradeep


People also ask

How do I fix Java net ConnectException connection refused?

ConnectException: Connection refused: 1) First try to ping the destination host, if the host is ping-able it means the client and server machine are in the network. 2) Try connecting to server host and port using telnet. If you are able to connect means something is wrong with your client code.

Why is 127.0 0.1 refused to connect?

0.1 (loopback address). So your client is trying to connect to any of the non-loopback addresses of your machine, while your server is listening only on the loopback address . So, no connection can be established. The solution to this problem is that connect to the same end point your server is listening on.

Is Java net ConnectException connection refused?

Ans: The Java connection refused is a case of a user trying to connect on TCP port but not able to access. There are many reasons, here are some possible causes why Java net ConnectException connection refused error occur: The server is not working. The client is not in the network.

What does Java net ConnectException mean?

java.net.ConnectException: Connection refused: connect is one of the most common networking exceptions in Java. This error comes when you are working with client-server architecture and trying to make TCP connection from the client to the server.


2 Answers

Since you have not specified you are connected to a server from the device or emulator so I guess you are using your application in the emulator.

If you are referring your localhost on your system from the Android emulator then you have to use http://10.0.2.2:8080/ Because Android emulator runs in a Virtual Machine therefore here 127.0.0.1 or localhost will be emulator's own loopback address.

Refer: Emulator Networking

like image 133
Vikas Patidar Avatar answered Sep 18 '22 14:09

Vikas Patidar


in android

Replace: String webServiceUrl = "http://localhost:8080/Service1.asmx"

With : String webServiceUrl = "http://10.0.2.2:8080/Service1.asmx"

Good luck!

like image 31
PhuocLuong Avatar answered Sep 18 '22 14:09

PhuocLuong