Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.net.ConnectException: fail to connect to localhost/127.0.0.1(port 8080): connect failed:ECONNREFUSED….(Codename One App)

After building an android application, I scanned the generated QRcode and install the application on galaxy s4 successfully. But when I try to do some search using the app I got the following exception:

 "java.net.ConnectException: fail to connect to localhost/127.0.0.1(port 8080): connect failed: ECONNREFUSED…." 

Please check the attached picture for more clarity.

The app works correctly on the simulator. I OFF the firewall of my system but that doesn't solve the issue. Please how can I solve this problem?

This issue applies to: NetBeans 8.0.2, GlassFish Server 4.1, Windows 7, Device: Samsung Galaxy S4

enter image description here

Best regards.

like image 512
Yahya-Imam Munir Avatar asked Apr 23 '16 13:04

Yahya-Imam Munir


People also ask

How do I resolve Java net ConnectException Connection refused connect?

net. 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.

What does Java net ConnectException Connection Refused no further information mean?

net. ConnectException: Connection refused: connect. It's quite possible that either you are providing incorrect host port combination or earlier host port combination has been changed on the server side. Check the latest configuration on both client and server side to avoid connection refused exception.


2 Answers

Inside the emulator, 127.0.0.1 refers to the emulator itself - not your local machine. You need to use ip 10.0.2.2, which is bridged to your local machine.

like image 146
EdwardGarson Avatar answered Oct 23 '22 11:10

EdwardGarson


It looks like you're trying to connect to localhost in your URL.

This probably works fine using the simulator, but you'll need to use an IP address or better yet a resolvable host name in your URL when you run the app in production.

Try changing your URL in this way. You can test for connectivity by using your phone's web browser, for example enter a URL (not using localhost!) of your web service in the browser and see what happens.

like image 29
ck1 Avatar answered Oct 23 '22 11:10

ck1