小编sou*_*ure的帖子

使用 React Native 时出现错误:“E/AndroidRuntime:致命异常:OkHttp Dispatcher”

2020-12-01 11:20:24.357 16113-16534/com.innerfit.app E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher
    Process: com.innerfit.app, PID: 16113
    java.lang.StringIndexOutOfBoundsException: String index out of range: -1
        at java.lang.String.substring(String.java:2064)
        at okhttp3.JavaNetCookieJar.decodeHeaderAsJavaNetCookies(JavaNetCookieJar.kt:98)
        at okhttp3.JavaNetCookieJar.loadForRequest(JavaNetCookieJar.kt:59)
        at com.facebook.react.modules.network.ReactCookieJarContainer.loadForRequest(ReactCookieJarContainer.java:44)
        at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:75)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:112)
        at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:71)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:112)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:87)
        at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.kt:184)
        at okhttp3.RealCall$AsyncCall.run(RealCall.kt:136)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:923)
Run Code Online (Sandbox Code Playgroud)

Axios 请求对于一些请求来说工作正常,但是发生了崩溃,之后就没有任何效果了。必须删除该应用程序并重新安装才能使其再次运行。

我尝试过的事情:

  1. 根据此 GitHub 问题,在所有请求中添加了 { 'Connection': 'close' } 但未修复它。https://github.com/facebook/react-native/issues/11016#issuecomment-336685459
  2. 在 Gradle 文件中添加了 okhttp3 依赖项。https://github.com/facebook/react-native/issues/27250#issuecomment-573111088
 dependencies {

     compile "com.squareup.okhttp3:okhttp:4.2.1"
     compile "com.squareup.okhttp3:logging-interceptor:4.2.1"
     compile "com.squareup.okhttp3:okhttp-urlconnection:4.2.1"
 }
Run Code Online (Sandbox Code Playgroud)

android react-native

6
推荐指数
1
解决办法
2124
查看次数

标签 统计

android ×1

react-native ×1