当我将 cookieJar 与我的
java.lang.NullPointerException
一起使用时,我得到 OkHttpClient.Builder()
。我不确定为什么会出现此错误以及如何修复此错误,每次发生这种情况时我都必须重新安装应用程序。
这是错误堆栈跟踪:
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.net.HttpCookie.getPath()' on a null object reference
at java.net.CookieManager.pathMatches(CookieManager.java:395)
at java.net.CookieManager.get(CookieManager.java:217)
at okhttp3.JavaNetCookieJar.loadForRequest(JavaNetCookieJar.java:59)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:84)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:88)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
at com.my.app.data.networking.ApiLogger.datadogLogger$lambda$0(ApiLogger.kt:60)
at com.my.app.data.networking.ApiLogger.$r8$lambda$IVB96D3u4ArgZv68i0G_W_fF2P0(Unknown Source:0)
at com.my.app.data.networking.ApiLogger$$ExternalSyntheticLambda0.intercept(Unknown Source:2)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:225)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
at com.my.app.di.module.RemoteModule.provideOkHttpClient$lambda$1(RemoteModule.kt:72)
at com.my.app.di.module.RemoteModule.$r8$lambda$JrHU6JXY7kX0VmaQ0CHUwiu2oyI(Unknown Source:0)
at com.my.app.di.module.RemoteModule$$ExternalSyntheticLambda0.intercept(Unknown Source:0)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:229)
at okhttp3.RealCall.execute(RealCall.java:81)
at retrofit2.OkHttpCall.execute(OkHttpCall.java:204)
at retrofit2.adapter.rxjava2.CallExecuteObservable.subscribeActual(CallExecuteObservable.java:46)
at io.reactivex.Observable.subscribe(Observable.java:12284)
at retrofit2.adapter.rxjava2.BodyObservable.subscribeActual(BodyObservable.java:35)
at io.reactivex.Observable.subscribe(Observable.java:12284)
at io.reactivex.internal.operators.observable.ObservableSubscribeOn$SubscribeTask.run(ObservableSubscribeOn.java:96)
at io.reactivex.Scheduler$DisposeTask.run(Scheduler.java:608)
at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:66)
at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:57)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
看起来您的 CookieStore 在从 get() 返回的列表中包含一个 null 元素。