android 127.0.0.1/localhost connection refused,在模拟器上应该用10.0.2.2访问你的电脑本机
调试中通过android simulator模拟器链接localhost或者127.0.0.1,因为我在电脑上面建立了apache,我的代码大概就是
URL url = new URL(urlString);
URLConnection urlconn = url.openConnection();
但是报错了!!
Exception 1:java.net.ConnectException: localhost/127.0.0.1:8080 -
Connection refused
问题是这样的,android模拟器(simulator)把它自己作为了localhost,也就是说,代码中使用localhost或者127.0.0.1来访问,都是访问模拟器自己!这是不行的!
如果你想在模拟器simulator上面访问你的电脑,那么就使用android内置的IP 10.0.2.2 吧, 10.0.2.2 是模拟器设置的特定ip,是你的电脑的别名alias
记住,在模拟器上用10.0.2.2访问你的电脑本机
android 127.0.0.1/localhost connection refused,在模拟器上应该用10.0.2.2访问你的电脑本机的更多相关文章
- 【MongoDB】 Failed to connect to 127.0.0.1:27017, reason: Connection refused
由于项目需要,在一台虚拟机上安装了MongoDB,但是在启动的时候,出现如下错误: [root@localhost bin]# ./mongo MongoDB shell version v3.4.0 ...
- 解决git Failed to connect to 127.0.0.1 port xxxx: Connection refused
某天,用git拉取,提交代码的时候出现了git Failed to connect to 127.0.0.1 port xxxx: Connection refused的问题, 开始百度,看了一通.都 ...
- Error: client: etcd cluster is unavailable or misconfigured; error #0: dial tcp 127.0.0.1:4001: getsockopt: connection refused
配置docker网络flannel时,配置etcd的key的时候出现以下错误 Error: client: etcd cluster is unavailable or misconfigured; ...
- Failed to connect to 127.0.0.1 port 1080: Connection refused package 问题解决方法
错误: fatal: unable to access 'https://github.com/******': Failed to connect to 127.0.0.1 port 1080: C ...
- zabbix-Get value from agent failed: cannot connect to [[127.0.0.1]:10050]: [111] Connection refused
监控zabbix服务端这台服务器,然后显示Get value from agent failed: cannot connect to [[127.0.0.1]:10050]: [111] Conne ...
- 我遇到的错误curl: (7) Failed to connect to 127.0.0.1 port 1086: Connection refused
今天我用curl命令,无论如何都是出现: curl: (7) Failed to connect to 127.0.0.1 port 1086: Connection refused 找了很久,不知道 ...
- curl: (7) Failed to connect to 127.0.0.1 port 1086: Connection refused
今天我用curl命令,无论如何都是出现: curl: (7) Failed to connect to 127.0.0.1 port 1086: Connection refused 找了很久,不知道 ...
- zabbix 启到不起来:active check configuration update from [127.0.0.1:10051] started to fail (cannot connect to [[127.0.0.1]:10051]: [111] Connection refused)
cat /var/log/zabbix_agent_log 查看日记出现报错:active check configuration update from [127.0.0.1:10051] star ...
- git时 Failed to connect to 127.0.0.1 port 1080: Connection refused
在公司换了一台电脑之后发现git clone 和 npm install都失败,报错为 fatal: unable to access 'https://github.com/netease-im/N ...
随机推荐
- Struts2入门示例
1.导入struts2需要的9个包到lib文件夹中 2.配置web.xml文件 <?xml version="1.0" encoding="UTF-8"? ...
- WKWebView的使用
代码地址如下:http://www.demodashi.com/demo/13431.html 前言 最近项目中的UIWebView被替换为了WKWebView,因此来总结一下WKWebView的使用 ...
- easyui datagrid动态设置行、列、单元格不允许编辑
Easyui datagrid 行编辑.列编辑.单元格编辑设置 功能: 动态对datagrid 进行行.列.单元格编辑进行设置不允许编辑. 禁用行编辑: 在编辑方法调用前,对选择的行进行判断,如果不允 ...
- 关于new与=号创建对象的区别
(1)先定义一个名为str的对String类的对象引用变量:String str: (2)[在[栈]中查找有没有存放值为"abc"的地址,如果没有,则开辟一个存放字面值为" ...
- python selenium --处理下拉框
下拉框是我们最常见的一种页面元素,对于一般的元素,我们只需要一次就定位,但下拉框里的内容需要进行两次定位,先定位到下拉框,再定位到下拉框内里的选项. drop_down.html <html&g ...
- Mac Yosemite上安装macvim和YouCompleteMe
今天在macvim上安装YouCompleteMe的时候,碰到一个运行vim崩溃的错误.查了半天终于解决! 先上一下安装macvim的过程 # install xcode and command li ...
- 在centos 5.11上安装pylint
上午花了两三个小时在折腾pylint的安装. 如果是普通的linux倒也简单,只用运行一个pip install pylint就行了. 可是偏偏那么巧,服务器的版本是centos 5.11 这个版本对 ...
- [svc]msmtp+mutt发附件,发邮件给多个人
环境:centos6.7 x86-64 内网有web服务器(curl可展示目录) #预安装软件 yum install lrzsz ntpdate sysstat dos2unix wget teln ...
- Visual Studio 环境配置
一.Productivity Power Tools 1.安装了之后有垂直的分隔线,取消 2.高亮选中匹配的代码 ① VS 2012 3.高亮当前的Tab选项卡
- linux下Samba服务配置
SMB是基于客户机/服务器型的协议,因而一台Samba服务器既可以充当文件共享服务器,也可以充当一个Samba的客户端,例如,一台在Linux 下已经架设好的Samba服务器,windows客户端就可 ...