我是Java新手,并且在android上编程。看看下面的代码:获取页面源代码的问题
TextView tv = new TextView(this);
URI uri;
HttpResponse response = null;
String str = "dupa2";
try {
uri = new URI("http://google.com");
HttpGet get = new HttpGet(uri);
HttpClient client = new DefaultHttpClient();
try {
response = client.execute(get);
HttpEntity enity = response.getEntity();
str = enity.toString();
str = "2";
} catch (IOException ex) {
tv.setText("blad");
Logger.getLogger(MainActivity.class.getName()).log(Level.SEVERE, null, ex);
}
} catch (URISyntaxException ex) {
tv.setText("blad");
Logger.getLogger(MainActivity.class.getName()).log(Level.SEVERE, null, ex);
}
tv.setText(str);
setContentView(tv);
它不工作,我没有想法,为什么:/ STR值为“dupa2”时,它应该是“2”(我补充它,因为我不知道怎么回事on)或“blad”)WTF?
我必须添加try ... catch语句吗? 由于提前, 克里斯
你需要看看你的logcat或徘徊无论是记录器发送它是输出。要查看stacktrace是什么,那会告诉你你的错误。我猜,你没有明确的互联网许可。 – Blundell 2011-03-31 15:13:05