java.net.ConnectException:无法连接到 localhost/127.0.0.1(端口 8080):连接失败:ECONNREFUSED ....(代号一个应用程序)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36811202/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.net.ConnectException: fail to connect to localhost/127.0.0.1(port 8080): connect failed:ECONNREFUSED….(Codename One App)
提问by Yahya-Imam Munir
After build 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:
构建android应用程序后,我扫描了生成的二维码并成功地在galaxy s4上安装了应用程序。但是当我尝试使用该应用程序进行一些搜索时,出现以下异常:
"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 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
此问题适用于:NetBeans 8.0.2、GlassFish Server 4.1、Windows 7、设备:Samsung Galaxy S4
Best regards.
此致。
采纳答案by ck1
It looks like you're trying to connect to localhost
in your URL.
看起来您正在尝试连接到localhost
您的 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.
这可能使用模拟器运行良好,但是当您在生产环境中运行应用程序时,您需要在 URL 中使用 IP 地址或更好的可解析主机名。
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.
尝试以这种方式更改您的 URL。您可以使用手机的 Web 浏览器测试连接性,例如在浏览器中输入 Web 服务的 URL(不使用 localhost!),看看会发生什么。
回答by EdwardGarson
From 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.
从模拟器来看, 127.0.0.1 指的是模拟器本身——而不是你的本地机器。您需要使用ip 10.0.2.2,它被桥接到您的本地机器。
HTH!
哼!