Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cache的空指针异常问题 #36

Closed
FlogFly opened this issue Oct 15, 2018 · 2 comments
Closed

cache的空指针异常问题 #36

FlogFly opened this issue Oct 15, 2018 · 2 comments

Comments

@FlogFly
Copy link

FlogFly commented Oct 15, 2018

目前不管是否设置了cache缓存,第一句一定会去执行,然后就有可能报空指针异常。
private void setCacheConfig() {
OkHttpConfig.defaultCachePath = this.context.getExternalCacheDir().getPath() + "/RxHttpCacheData";
if (this.isCache) {
Cache cache;
if (!TextUtils.isEmpty(this.cachePath) && this.cacheMaxSize > 0L) {
cache = new Cache(new File(this.cachePath), this.cacheMaxSize);
} else {
cache = new Cache(new File(OkHttpConfig.defaultCachePath), 104857600L);
}

            OkHttpConfig.okHttpClientBuilder.cache(cache).addInterceptor(new NoNetCacheInterceptor()).addNetworkInterceptor(new NetCacheInterceptor());
        }

    }

里面的第一句,如果设备获取getExternalCacheDir是null,那么后面还会执行getpath,然后就报空指针异常了。

@lygttpod
Copy link
Owner

getExternalCacheDir确实有可能会为null,没考虑全,感谢提出问题,会尽快修复的

image

@lygttpod
Copy link
Owner

新版本已修复

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants