0

我有一个外部 .hash 文件,我厌倦了将其作为一个简单的远程文本文件阅读:

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)
4

1 回答 1

0

您是在调试模式还是常规模式下运行它?该source not found消息似乎表明您正在尝试进入没有附加源的代码。

你也添加 <uses-permission android:name="android.permission.INTERNET" /> 到你的AndroidManifest.xml?

于 2012-09-24T22:07:49.933 回答