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() 方法可能返回的空值。允许该方法只抛出其声明的异常而不在内部捕获它们会更好。

于 2013-05-10T08:50:33.497 回答