【问题标题】:Android - Unknown Error when trying to use networkingAndroid - 尝试使用网络时出现未知错误
【发布时间】:2009-08-12 14:27:44
【问题描述】:

我刚刚开始开发 Android 应用程序。我的网络有点问题。如果我运行以下代码,我会收到“未知错误”异常消息:

import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.client.ClientProtocolException;
import.org.apache.http.client.methods.HttpGet;


import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class Menu extends Activity {
    /** Called when the activity is first created. */
    @Override
   public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    DefaultHttpClient client = new DefaultHttpClient();

    HttpGet method = new HttpGet("http://www.google.com");

    try {
        client.execute(method);
        TextView t = (TextView) findViewById(R.id.myTextView);
        t.setText("Ok");
    } catch (ClientProtocolException e) {
        TextView t = (TextView) findViewById(R.id.myTextView);
        t.setText(e.getMessage());
    } catch (IOException e) {
        TextView t = (TextView) findViewById(R.id.myTextView);
        t.setText(e.getMessage());
    }

    }
}

我一直在查找错误,它似乎很常见。这是模拟器上DNS解析的问题。但是,我可以毫无问题地使用模拟器上的浏览器并访问我想要的任何网站。我也试过用 IP 地址替换域,但没有成功。

我该如何解决这个问题?我正在使用 Windows Vista 并使用 ADT 插件在 eclipse 中进行开发。

【问题讨论】:

    标签: android eclipse exception networking dns


    【解决方案1】:

    根据这个blog,您需要在您的AndroidManifest.xml 中为您的应用程序设置“INTERNET”权限

    【讨论】:

      猜你喜欢
      • 2020-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-11
      • 1970-01-01
      • 2018-08-26
      • 2019-01-13
      相关资源
      最近更新 更多