2016-05-19 42 views
0

這裏後使用吹氣是我的堆棧跟蹤:的Android IllegalStateException異常:嘗試調用結束

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

,這裏是從下載服務代碼:

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

隨機情況下會發生此錯誤。下載服務用於下載應用程序的新版本。

回答

0

請注意,您不能關閉從與您的下載服務(即正在調用InputStream.read的服務)不同的線程下載InputStream。

您是否有另一個線程,試圖通過InputStream.close()api關閉流?這種行爲會導致這種運行時異常。在最近的OkHttp版本中,會在閉合線程中產生一些類似的異常。請參閱以下參考:https://github.com/square/okhttp/issues/1842

相關問題