Android 在模拟器中测试正常,但不能在手机上测试

Android 在模拟器中测试正常,但不能在手机上测试,android,emulation,Android,Emulation,我在模拟器中测试它是否可以正确运行。但是我在电话上测试,它总是抛出一个异常 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); T

我在模拟器中测试它是否可以正确运行。但是我在电话上测试,它总是抛出一个异常

  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);  The two sentence added on the phone, it still can not run
   //   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 "Connection errors!";
    }
  }

我在创建项目时检查API4。并在仿真器Android1.6中进行测试。测试手机是否在安卓2.3.3上。我还测试了android-x86 2.2 JAR计算机。没问题。我将
添加到
AndroidManifest.xml
中。我不知道原因。任何人的意见都是值得感谢的。

您将此函数称为什么线程?你无法在UI线程中创建连接

发布你的logcat输出你检查过你的手机是否连接到互联网了吗?Android中的2.2+版本要求在线程中调用网络连接或异步任务,然后这将解决我想Tr提到的问题ần SĩLong