0

リモート テキスト ファイルを読み取り、その内容をテキスト ビューに表示したいと考えています。このコードを書きましたが、テキスト ファイルから情報が取得されず、「強制停止」エラーが発生します。この問題の原因を見つけたり、解決したりするにはどうすればよいですか? 私のコードに何か問題はありませんか?

private class DownloadFile extends AsyncTask<String, Integer, Void> {
protected void doInBackground() {
    try {
        URL url = new URL("http://host/f.txt");       
        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
        String line = null;
        while ((line = in.readLine()) != null) {
        //get lines
        }
        in.close();
        lbl.setText(line);
    } 
    catch (MalformedURLException e) {
        e.printStackTrace();
    } 
    catch (IOException e) {
        e.printStackTrace();
    }
}
protected void onProgressUpdate() {
    //called when the background task makes any progress
}
protected void onPreExecute() {
     //called before doInBackground() is started
}
protected void onPostExecute() {
     //called after doInBackground() has finished 
}
@Override
protected Void doInBackground(String... arg0) {
    // TODO Auto-generated method stub
    return null;
}
}

と私の onCreate コード:

DownloadFile d=new DownloadFile();
d.doInBackground();

私の問題を解決してください!

4

3 に答える 3