android 模拟器测试没有关问题,真机网络连接错误
android 模拟器测试没问题,真机网络连接异常
抛出异常部分的代码,在真机运行时总是出现连接出现错误!!!,
public static String doGet(String url) {
try {
HttpGet method = new HttpGet(url);
DefaultHttpClient client = new DefaultHttpClient();
// HttpHost proxy = new HttpHost("10.0.0.172", 80);这两句加不加进去真机都不行
// client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
method.setHeader("Connection", "Keep-Alive");
HttpResponse response = client.execute(method);
int status = response.getStatusLine().getStatusCode();
if (status != HttpStatus.SC_OK)
throw new Exception("");
return EntityUtils.toString(response.getEntity(), "UTF-8");
} catch (Exception e) {
return "连接出现错误!!!";
}
}
创建项目时选的是API4, 测试时的模拟器是android 1.6,真机是android 2.3.3
模拟器运行时网络连接没问题,但真机就抛出异常。我也在电脑的android-x86 2.2通用版测试也没问题。
在AndroidManifest.xml里已经加入<uses-permission android:name="android.permission.INTERNET"/>。
------解决方案--------------------
现在使用android 2.3.3 模拟器也可以,但真机就是不行。
------解决方案--------------------
找到原因了,是手机里的问题,与程序无关。
------解决方案--------------------
你好,我也碰到这个问题,手机的什么原因啊?紧急求救!我运行在平板上不行,老报错
------解决方案--------------------
求怎么解决啊?
------解决方案--------------------
把你的logcat输出的内容粘出来。
在这个函数中你调用了什么线程?你不可以在UI线程里创建连接。
抛出异常部分的代码,在真机运行时总是出现连接出现错误!!!,
public static String doGet(String url) {
try {
HttpGet method = new HttpGet(url);
DefaultHttpClient client = new DefaultHttpClient();
// HttpHost proxy = new HttpHost("10.0.0.172", 80);这两句加不加进去真机都不行
// client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
method.setHeader("Connection", "Keep-Alive");
HttpResponse response = client.execute(method);
int status = response.getStatusLine().getStatusCode();
if (status != HttpStatus.SC_OK)
throw new Exception("");
return EntityUtils.toString(response.getEntity(), "UTF-8");
} catch (Exception e) {
return "连接出现错误!!!";
}
}
创建项目时选的是API4, 测试时的模拟器是android 1.6,真机是android 2.3.3
模拟器运行时网络连接没问题,但真机就抛出异常。我也在电脑的android-x86 2.2通用版测试也没问题。
在AndroidManifest.xml里已经加入<uses-permission android:name="android.permission.INTERNET"/>。
------解决方案--------------------
现在使用android 2.3.3 模拟器也可以,但真机就是不行。
------解决方案--------------------
找到原因了,是手机里的问题,与程序无关。
------解决方案--------------------
你好,我也碰到这个问题,手机的什么原因啊?紧急求救!我运行在平板上不行,老报错
------解决方案--------------------
求怎么解决啊?
------解决方案--------------------
把你的logcat输出的内容粘出来。
在这个函数中你调用了什么线程?你不可以在UI线程里创建连接。