gpt4 book ai didi

android - 使用 okhttp-3.12.0 Android 找不到类 "kotlin.text.Charsets"错误

转载 作者:搜寻专家 更新时间:2023-11-01 09:22:31 24 4
gpt4 key购买 nike

代码没有问题所以我只是复制错误。我正在使用 okhttp 3.12.0 从互联网上获取一些东西(在 Android 编程中)

下一行可能是主要问题:

java.lang.ClassNotFoundException: Didn't find class "kotlin.text.Charsets"

AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
Process: com.example.infitualer.ipdemo, PID: 3306
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:325)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lkotlin/text/Charsets;
at okio.Buffer.<clinit>(Buffer.kt:2212)
at okhttp3.ResponseBody.create(ResponseBody.java:210)
at okhttp3.internal.Util.<clinit>(Util.java:62)
at okhttp3.internal.Util.immutableList(Util.java:0)
at okhttp3.OkHttpClient.<clinit>(OkHttpClient.java:127)
at com.example.infitualer.ipdemo.MainActivity$IpTask.doInBackground(MainActivity.java:34)
at com.example.infitualer.ipdemo.MainActivity$IpTask.doInBackground(MainActivity.java:25)
at android.os.AsyncTask$2.call(AsyncTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) 
at java.lang.Thread.run(Thread.java:761) 
Caused by: java.lang.ClassNotFoundException: Didn't find class "kotlin.text.Charsets" on path: DexPathList[[zip file "/data/app/com.example.infitualer.ipdemo-1/base.apk", zip file "/data/app/com.example.infitualer.ipdemo-1/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.infitualer.ipdemo-1/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.infitualer.ipdemo-1/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.infitualer.ipdemo-1/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.infitualer.ipdemo-1/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.infitualer.ipdemo-1/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.infitualer.ipdemo-1/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.infitualer.ipdemo-1/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.infitualer.ipdemo-1/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.infitualer.ipdemo-1/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.infitualer.ipdemo-1/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.infitualer.ipdemo-1/lib/x86, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at okio.Buffer.<clinit>(Buffer.kt:2212) 
at okhttp3.ResponseBody.create(ResponseBody.java:210) 
at okhttp3.internal.Util.<clinit>(Util.java:62) 
at okhttp3.internal.Util.immutableList(Util.java:0) 
at okhttp3.OkHttpClient.<clinit>(OkHttpClient.java:127) 
at com.example.infitualer.ipdemo.MainActivity$IpTask.doInBackground(MainActivity.java:34) 
at com.example.infitualer.ipdemo.MainActivity$IpTask.doInBackground(MainActivity.java:25) 
at android.os.AsyncTask$2.call(AsyncTask.java:305) 
at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) 
at java.lang.Thread.run(Thread.java:761) 

最佳答案

您必须为 Okio 使用 Kotlin stdlib 依赖项。要么使用 OkHttp 所依赖的 Okio 1.1.15,要么包括 Okio 2.0 的依赖项 Kotlin stdlib。

下载Okio 1.1.15.jar从 MvnRepository 添加到 lib 文件夹,然后配置依赖

implementation files('libs/okio-1_15_0.jar')

关于android - 使用 okhttp-3.12.0 Android 找不到类 "kotlin.text.Charsets"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53573712/

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