在安卓開發的路上好多坑,這不今天又忙活了大半天,原因是報了這麼個錯:
err: java.io.IOException: closed
at okio.RealBufferedSource$1.read(RealBufferedSource.java:436)
at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
at android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:742)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:718)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:756)
這是在使用OKHttpClient下載圖片的時候發生的,
出現的IO異常是: 已經關閉, 搞了半天不知道怎麼解決
後來才知道原來 response.body().string() 只能用一次, 而我下面代碼裏用了兩次, 第一次用完的時候輸入流自動被回收了,註釋了下面的代碼,就沒事兒了, 記住 response.body().string()只能用一次.
記錄一下, 下次不會再採坑.