gpt4 book ai didi

java - 如何修复 java.util.concurrent.ExecutionException :

转载 作者:行者123 更新时间:2023-12-01 19:19:25 25 4
gpt4 key购买 nike

我在 Google Play Android Vitals 上看到了一些来自以下代码的崩溃报告:

val currentUser = auth.currentUser

if (currentUser != null) {
sessionToken = Tasks.await(currentUser.getIdToken(true)).token
newRequest = request
.newBuilder()
.header(AUTHORIZATION, "$BEARER $sessionToken")
.build()
} else {
newRequest = request
.newBuilder()
.build()
}

出现问题的行是这样的:sessionToken = Tasks.await(currentUser.getIdToken(true)).token

auth 是 FirebaseUser 对象。该代码位于拦截器中,它为需要它的请求添加授权 token 。

我不知道如何解决这个问题。我正在考虑用

包装所有代码
syncronized(this) {
//here goes the code
}

但我不确定这是否能解决我的问题。

完整的堆栈跟踪:

    java.lang.Error: 
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1173)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:641)
at java.lang.Thread.run (Thread.java:764)
Caused by: java.util.concurrent.ExecutionException:
at com.google.android.gms.tasks.Tasks.zzb (Unknown Source:61)
at com.google.android.gms.tasks.Tasks.await (Unknown Source:23)
at com.cofedistrict.data.remote.interceptors.TokenHeaderInterceptor.intercept (TokenHeaderInterceptor.kt:37)
at okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:121)
at okhttp3.logging.HttpLoggingInterceptor.intercept (HttpLoggingInterceptor.java:213)
at okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:121)
at okhttp3.RealCall.getResponseWithInterceptorChain (RealCall.java:200)
at okhttp3.RealCall$AsyncCall.execute (RealCall.java:147)
at okhttp3.internal.NamedRunnable.run (NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1167)
Caused by: java.util.concurrent.ExecutionException: com.google.firebase.auth.FirebaseAuthInvalidUserException: The user's credential is no longer valid. The user must sign in again.
at com.google.firebase.auth.api.internal.zzdx.zza
at com.google.firebase.auth.api.internal.zzfa.zza
at com.google.firebase.auth.api.internal.zzet.zza
at com.google.firebase.auth.api.internal.zzev.zza
at com.google.firebase.auth.api.internal.zzed.zza
at com.google.android.gms.internal.firebase_auth.zza.onTransact
at android.os.Binder.execTransact (Binder.java:739)

最佳答案

改变

val currentUser = auth.currentUser

val currentUser = FirebaseAuth.getInstance().currentUser

然后检查

if (currentUser != null) {
//your code here
}

如果我的解决方案不能解决您的问题,请检查一下它说

Caused by: java.util.concurrent.ExecutionException: com.google.firebase.auth.FirebaseAuthInvalidUserException: The user's credential is no longer valid

因此请使用有效的登录凭据。

关于java - 如何修复 java.util.concurrent.ExecutionException :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59379016/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com