0

次のエラーが発生しました

05-10 11:14:47.925: W/System.err(9681): java.io.IOException: BufferedInputStream is closed
05-10 11:14:47.925: W/System.err(9681):     at java.io.BufferedInputStream.streamClosed(BufferedInputStream.java:118)
05-10 11:14:47.925: W/System.err(9681):     at java.io.BufferedInputStream.available(BufferedInputStream.java:112)
05-10 11:14:47.925: W/System.err(9681):     at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
05-10 11:14:47.925: W/System.err(9681):     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:529)
05-10 11:14:47.925: W/System.err(9681):     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:601)
05-10 11:14:47.925: W/System.err(9681):     at com.laroche.NewsMedia.getImageBitmap(NewsMedia.java:132)
05-10 11:14:47.932: W/System.err(9681):     at com.laroche.News.getNewsListByCategoryId(News.java:113)
05-10 11:14:47.932: W/System.err(9681):     at com.laroche.MainActivity$GetDataTask.doInBackground(MainActivity.java:112)
05-10 11:14:47.932: W/System.err(9681):     at com.laroche.MainActivity$GetDataTask.doInBackground(MainActivity.java:1)
05-10 11:14:47.932: W/System.err(9681):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
05-10 11:14:47.932: W/System.err(9681):     at java.util.concurrent.FutureTask.run(FutureTask.java:234)
05-10 11:14:47.932: W/System.err(9681):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
05-10 11:14:47.932: W/System.err(9681):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
05-10 11:14:47.932: W/System.err(9681):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
05-10 11:14:47.932: W/System.err(9681):     at java.lang.Thread.run(Thread.java:856)

このコード行で:

BufferedInputStream bufferedInputStream = null;
    Bitmap bmp = null;
    String urlString = "http://ma2too3a.com:8084/NewsImages/"+imageName;
    try {
        bufferedInputStream = new BufferedInputStream(ws.OpenHttpConnection(urlString));
        bmp = BitmapFactory.decodeStream(bufferedInputStream);

        saveImage(bmp,imageName,c);
        bufferedInputStream.close();


    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

OpenHttpConnection()関数は次のとおりです。

public InputStream OpenHttpConnection(String urlString) throws IOException{
    InputStream in = null;
    int respobse = -1;

    URL url = new URL(urlString);
    URLConnection conn = url.openConnection();
    if(!(conn instanceof HttpURLConnection))
        throw new IOException("It's not HTTP connection");
    try{
        HttpURLConnection httpConn = (HttpURLConnection) conn;
        httpConn.setAllowUserInteraction(false);
        httpConn.setInstanceFollowRedirects(true);
        httpConn.setRequestMethod("GET");
        httpConn.connect();

        respobse = httpConn.getResponseCode();
        if(respobse == HttpURLConnection.HTTP_OK){
            in= httpConn.getInputStream();
            Log.d("HTTP connection","OK");
        }
    }catch (IOException e) {
        Log.e("HTTP ERROR",e.toString());
        throw new IOException();
    }
    return in;
}
4

1 に答える 1

0

OpenConnection() メソッドからの null 戻りの可能性を無視しています。そのメソッドが宣言された例外をスローし、内部でキャッチしないようにすることをお勧めします。

于 2013-05-10T08:50:33.497 に答える