2012-09-24 40 views
0

我有一個外部.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) 
+0

請發佈logcat錯誤輸出。 – HelmiB

回答

0

你在調試模式或常規模式下運行呢? source not found消息似乎表明您正在嘗試插入沒有源代碼的代碼。

也有你加入 <uses-permission android:name="android.permission.INTERNET" />AndroidManifest.xml

+0

感謝您的回覆,但我確實添加了必要的權限。 – PovilasID

+0

第一部分呢?你在調試還是常規模式下運行? – DavidS

+0

你是什麼意思? – PovilasID