我有一個外部.hash文件,我厭倦了閱讀的簡單遠程文本文件:如何正確使用傳遞給android線程的參數?
private class getHash extends AsyncTask<String, Void, String>{
@Override
protected String doInBackground(String... params) {
String str = null;
try {
// Create a URL for the desired page
URL url = new URL(params[0]);
// Read all the text returned by the server
InputStream is = url.openStream();//The line it crashes on
InputStreamReader isr = new InputStreamReader(is);
BufferedReader in = new BufferedReader(isr);
str = in.readLine();
in.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
@Override
protected void onPostExecute(String result) {
hash = result;
}
}
然後我打電話螺紋:
getHash hashThread = new getHash();
hashThread.execute(new String[]{"http://www......................hash"});
在班上注意的行的所有執行停下來,我得到了優雅的Source not found
崩潰。
logcat中給出了這樣的錯誤:
W/dalvikvm(724): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
請發佈logcat錯誤輸出。 – HelmiB