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 ...
随机推荐
- hibernate 组件映射
注解方式: import javax.persistence.Embedded; import javax.persistence.Entity; import javax.persistence ...
- Python-绑定与未绑定方法通俗讲解
像函数一样,Python中的类方法也是一种对象.由于既可以通过实例也可以通过类来访问方法,所以在Python里有两种风格: 未绑定的类方法:没有self 通过类来引用方法返回一个未绑定方法 ...
- 自闭合标签-主动闭合标签-meta-link标签
<!DOCTYPE html><!--规定标准的html--><!--一个页在只有一对html标签--><!--标签的属性 指定英文--><htm ...
- Latex中设置字体颜色
在用Latex时,想要使用不同颜色来突出某些关键点,有以下三种方案: 1.组合red.green和blue的值合成我们想要的颜色 \usepackage{color} \textcolor[rgb]{ ...
- CSS/JQuery元素选择器之&&和||,选择器的逻辑操作
使用CSS或JQuery选中元素的时候.非常多时候我们须要对条件进行&&或者||操作. JQuery或者CSS中的||操作是非经常常使用的.也非常easy,就是通过逗号来分隔的. se ...
- NYOJ 10 skiing (深搜和动归)
skiing 时间限制:3000 ms | 内存限制:65535 KB 难度:5 描写叙述 Michael喜欢滑雪百这并不奇怪. 由于滑雪的确非常刺激.但是为了获得速度.滑的区域必须向下倾斜.并且 ...
- Web檢測
腾讯电脑管家http://guanjia.qq.com/online_server/webindex.html 安全联盟http://zhanzhang.anquan.org/physical/my_ ...
- hdu 1711 Number Sequence KMP 基础题
Number Sequence Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- C# asp.net页面常用语法,页面包含
搞.net开发这么多年,知道和用过包含include指令吗? <%@ Page Language="C#" AutoEventWireup="true" ...
- /proc/version 的生成过程
/proc/version 的生成过程 通常我们cat /proc/version时,会显示kernel相关的版本.编译等信息 那么问题来了,这些信息是怎么生成的呢? /proc/version文件是 ...