【发布时间】:2015-11-22 05:44:54
【问题描述】:
设置
File cacheDirectory = new File(app.getCacheDir(), "network_cache");
if (!cacheDirectory.exists()) {
cacheDirectory.mkdir();
}
Cache cache = new Cache(cacheDirectory, CACHE_MAX_SIZE);
OkHttpClient okHttpClient = new OkHttpClient();
okHttpClient.networkInterceptors().add(new StethoInterceptor());
okHttpClient.setCache(cache);
导致此异常且不可能被捕获:
Process: xx.xx.xx.debug, PID: 8227
java.lang.NullPointerException: Attempt to invoke virtual method 'okio.BufferedSource com.squareup.okhttp.ResponseBody.source()' on a null object reference
at com.squareup.okhttp.internal.http.HttpEngine.cacheWritingResponse(HttpEngine.java:935)
at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:821)
at com.squareup.okhttp.Call.getResponse(Call.java:268)
at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:224)
at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:195)
at com.squareup.okhttp.Call.access$100(Call.java:34)
at com.squareup.okhttp.Call$AsyncCall.execute(Call.java:162)
at com.squareup.okhttp.internal.NamedRunnable.run(NamedRunnable.java:33)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
这发生在 okhttp 2.5 和 okhttp-ws 2.5 上。使用 okhttp 2.4 和 okhttp-ws 2.4 我们遇到了没有堆栈跟踪的崩溃
【问题讨论】: