日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java build返回空值_OKHTTP拦截器不断返回空值并使应用程序崩溃

發布時間:2025/3/17 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java build返回空值_OKHTTP拦截器不断返回空值并使应用程序崩溃 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我有一個OKHTTP客戶機,它使用我的自定義網絡攔截器將令牌插入請求頭中。

我不斷地得到例外

E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher

Process: com.edstart.tazuzu, PID: 32093

java.lang.NullPointerException: interceptor com.edstart.tazuzu.RestAPI.RequestsErrorInterceptor@2bde70f returned null

at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:157)

at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)

at com.edstart.tazuzu.RestAPI.TazuzuRequestsInterceptor.intercept(TazuzuRequestsInterceptor.kt:30)

at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)

at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45)

at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)

at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)

at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)

at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)

at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)

at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)

at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)

at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126)

at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)

at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)

at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:254)

at okhttp3.RealCall$AsyncCall.execute(RealCall.java:200)

at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)

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)

我試過用Try/Catch包圍攔截器。同時也拋出錯誤,以避免應用程序崩潰,但沒有很好的效果。

攔截器代碼:

package com.edstart.tazuzu.RestAPI

import android.util.Log

import com.edstart.tazuzu.Managers.ServerManager

import okhttp3.Interceptor

import okhttp3.Response

import java.net.InetAddress

import kotlin.Exception

/**

* interceptor for the tazuzu api requests to insert the token before the request

* send to the server (for authentication)

*/

class TazuzuRequestsInterceptor : Interceptor {

override fun intercept(chain: Interceptor.Chain?): Response? {

try {

if (!isInternetAvailable()) {

throw Exception()

} else {

var request = chain?.request()

if (request != null) {

val builder = request.newBuilder()

if (builder != null) {

builder.addHeader("x-access-token", ServerManager.token)

request = builder.build()

if (request != null && chain != null) {

return chain.proceed(request)

}

}

}

}

} catch (e: java.lang.Exception) {

Log.e("###", e.toString())

throw e

}

return null

}

private fun isInternetAvailable(): Boolean {

return try {

val ipAddr = InetAddress.getByName("google.com")

//You can replace it with your name

!ipAddr.equals("")

} catch (e: Exception) {

false

}

}

請幫忙,尋找控制異常的方法,以避免應用程序崩潰。

總結

以上是生活随笔為你收集整理的java build返回空值_OKHTTP拦截器不断返回空值并使应用程序崩溃的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。