49

我正在开发一个应用程序,我想我想做的是从 android 中的服务器数据库接收数据。所以我开始运行一些教程。我找到了一个正在做我想做的事的人。但我得到:

detailMessage   "failed to connect to localhost/127.0.0.1 (port 8080): connect failed: ECONNREFUSED (Connection refused)" (id=830021648792) 

本教程的完整代码在这里链接

错误发生在:

OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());

我检查了:

  • 防火墙被禁用
  • 平工作
  • 连接字符串与我从服务器管理界面运行 servlet 时完全相同http://localhost:8080/Requestor/RQSRV - servlet 正在运行

我的配置:

  • 服务器:玻璃鱼 4.0
  • Android 应用程序 - 在 Eclipse 中开发
  • Servlet - 在 NetBeans 中开发
4

2 回答 2

143

To access your PC localhost from Android emulator, use 10.0.2.2 instead of 127.0.0.1. localhost or 127.0.0.1 refers to the emulated device itself, not the host the emulator is running on.

Reference: https://developer.android.com/studio/run/emulator-networking#networkaddresses

For Genymotion use: 10.0.3.2 instead of 10.0.2.2

于 2013-08-21T12:38:18.377 回答
-1

如果您使用的是 genymotion,请转到命令提示符类型 ipconfig -find 以太网适配器 virtualBox 仅主机网络:-find 用于 Ipv4 地址..........................192.1**.**.*复制

http://192.1 .*/文件夹名/文件名/文件名.json 或文件名.php

检查它是否工作在模拟器中复制粘贴到浏览器中,您应该在浏览器中找到您正在查看的文件。

对不起英语..这对我有用希望这可能对某人有所帮助..谢谢你..

于 2016-09-09T19:07:14.993 回答