所以我使用下面的代碼從一個不同的舊帖子,但有一個部分的問題,行:HttpGet request = new HttpGet(url);
不起作用。在url中,我放置了類似www.stackoverflow.com
的東西,但是其中一部分不會讓代碼編譯。我基本上試圖從HTML網站拉文字。完整的代碼:HttpGet無法識別url
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(www.stackoverflow.com);
HttpResponse response = client.execute(request);
String html = "Toronto-GTA";
InputStream in = response.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuilder str = new StringBuilder();
String line = null;
while((line = reader.readLine()) != null)
{
str.append(line);
}
in.close();
html = str.toString();
}
for HttpGet request = new HttpGet(www.stackoverflow.com);我改成它(「www.stackoverflow.com」);正如許多人所建議的那樣,但其他行如「HttpResponse response = client.execute(request);」返回編譯錯誤,所有這些:未處理的異常類型IOException,eclipse中的大多數快速修復提示「Surroned with try/catch」 – Clozecall 2011-04-22 19:08:16