2012-09-24 41 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