0
我刚开始开发Android应用程序。我在网络方面遇到了一些问题。如果我运行下面的代码我得到一个“未知错误”异常消息: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());
}
}
}
我已经lookign了错误,它似乎相当普遍。这是模拟器上DNS解析的问题。但是,我可以在模拟器上使用浏览器而不会出现问题,并访问我想要的任何网站。我也尝试用IP地址替换域名,但没有运气。
我该如何解决这个问题?我正在使用Windows Vista并在Eclipse中使用ADT插件进行开发。