Android IllegalStateException:在调用end之后尝试使用Inflater [英] Android IllegalStateException: attempt to use Inflater after calling end

查看:67
本文介绍了Android IllegalStateException:在调用end之后尝试使用Inflater的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的Stacktrace:

Here is my Stacktrace:

<StackTrace>java.lang.IllegalStateException: attempt to use Inflater after calling end
    at java.util.zip.Inflater.checkOpen(Inflater.java:332)
    at java.util.zip.Inflater.setInput(Inflater.java:312)
    at com.android.okhttp.okio.InflaterSource.refill(InflaterSource.java:106)
    at com.android.okhttp.okio.InflaterSource.read(InflaterSource.java:62)
    at com.android.okhttp.okio.GzipSource.read(GzipSource.java:80)
    at com.android.okhttp.okio.RealBufferedSource$1.read(RealBufferedSource.java:374)
    at java.io.InputStream.read(InputStream.java:162)
    at com.myProgram.services.DownloadService.onHandleIntent(DownloadService.java:58)
    at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:66)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:158)
    at android.os.HandlerThread.run(HandlerThread.java:61)
</StackTrace>

这是DownloadService的代码:

and here is the code from DownloadService:

 InputStream input = connection.getInputStream();
 byte data[] = new byte[1024];
        long total = 0;
        int count;
        while ((count = input.read(data)) != -1) {
            total += count;
            Bundle resultData = new Bundle();
            resultData.putInt("progress" ,(int) (total * 100 / fileLength));
            receiver.send(U_PROGRESS, resultData);
            output.write(data, 0, count);
        }

58行是:

while ((count = input.read(data)) != -1) {

在随机情况下会发生此错误.下载服务用于下载该应用程序的新版本.

This error occurs in random cases. Download service is used to download new version of the app.

推荐答案

请注意,您无法从与下载服务不同的线程(即正在调用InputStream.read的线程)关闭正在下载的InputStream.

Note that you cannot close the downloading InputStream from a different thread than your download service (i.e. the one which is calling InputStream.read).

您是否有另一个线程正试图使用​​InputStream.close()API关闭流?这样的行为将导致这种运行时异常.在较新版本的OkHttp上,关闭线程将产生一些类似的异常.请参阅下面的参考: https://github.com/square/okhttp/issues/1842

Do you have another thread that by any chance is trying to close the stream using InputStream.close() api? such a behavior will cause this kind of runtime exception. On more recent versions of OkHttp, a somewhat similar exception will be produced from the closing thread. See below for a reference: https://github.com/square/okhttp/issues/1842

这篇关于Android IllegalStateException:在调用end之后尝试使用Inflater的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆