最新消息:20190717 VPS服务器:Vultr新加坡,WordPress主题:大前端D8,统一介绍入口:关于

【已解决】java中调用OkHttp出错:Exception in thread “main” java.lang.NoClassDefFoundError: kotlin/TypeCastException

Java crifan 20浏览 0评论
折腾:
【未解决】Mac的Java中使用OkHttp去进行基本的网络请求
期间,运行OkHttp的代码:
OkHttpClient client = new OkHttpClient();
出错:
Exception in thread "main" java.lang.NoClassDefFoundError: kotlin/TypeCastException
    at okhttp3.ResponseBody.create(ResponseBody.java:210)
    at okhttp3.internal.Util.<clinit>(Util.java:60)
    at okhttp3.OkHttpClient.<clinit>(OkHttpClient.java:123)
    at EmulateLoginBaidu.<init>(EmulateLoginBaidu.java:8)
    at EmulateLoginBaidu.main(EmulateLoginBaidu.java:26)
Caused by: java.lang.ClassNotFoundException: kotlin.TypeCastException
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 5 more
Disconnected from the target VM, address: '127.0.0.1:59602', transport: 'socket'
OkHttp Exception in thread “main” java.lang.NoClassDefFoundError: kotlin/TypeCastException
java – kotlin/TypeCastException when trying to create OkHttpClient object – Stack Overflow
eclipse – java.lang.NoClassDefFoundError: kotlin/TypeCastException when running code using OkHttp – Stack Overflow
kotlin stdlib and stdlib-common
intellij idea – java.lang.NoClassDefFoundError: kotlin/jvm/internal/Intrinsics – Stack Overflow
java – kotlin/TypeCastException when trying to create OkHttpClient object – Stack Overflow
Kotlin项目类找不到bug:java.lang.ClassNotFoundException: kotlin.reflect.Kotlin Reflect Internal Error – 熊本同学 – CSDN博客
java – OkHttp NetBeans NoClassDefFoundError – Qaru
Download kotlin-stdlib JAR file with all dependencies
kotlin stdlib
kotlin stdlib stdlib-common
kotlin/libraries/stdlib/common at master · JetBrains/kotlin
idea add kotlin stdlib stdlib-common
gradle – How to fix conflicting Kotlin dependency in IntelliJ IDEA? – Stack Overflow
intellij idea 如何添加 kotlin stdlib stdlib-common
intellij idea how add kotlin stdlib
Kotlin – Plugins | JetBrains
How to see Kotlin stdlib source code in Intellij? – Stack Overflow
Getting Started with IntelliJ IDEA – Kotlin Programming Language
Using Gradle – Kotlin Programming Language
intellij idea – Using kotlin-stdlib 1.1.51 but kotlin-runtime 1.3 is loaded – Stack Overflow
intellij idea – How to properly configure Kotlin plugin for Gradle? – Stack Overflow
intellij idea – How can I create a Kotlin project that builds with Gradle? – Stack Overflow
IntelliJ IDEA Minimal Survival Guide – Hadi Hariri
https://plugins.jetbrains.com/plugin/6954-kotlin
->
下载:
Update Details – Kotlin 1.3.0-release-Studio3.4-2 | Plugins
对应的:
https://plugins.jetbrains.com/files/6954/51807/kotlin-plugin-1.3.0-release-Studio3.4-2.zip?updateId=51807&pluginId=6954
希望可以,下载到jar
然后可以导入IDEA中
有我要的:
kotlin-stdlib.jar
kotlin-stdlib-common.jar
去导入试试
结果只导入了一个:
kotlin-stdlib.jar
再去导入:
kotlin-stdlib-common.jar
结果提示:
此处在
External Libraries中就可以看到了:
然后再去调试试试,能否解决问题。
终于就可以了,不会抛出异常了:
【总结】
此处是去调试OkHttp的库,其中:
OkHttpClient client = new OkHttpClient();
报错:
Exception in thread “main” java.lang.NoClassDefFoundError: kotlin/TypeCastException
解决办法是:
去IntelliJ IDEA的所属公司的官网:
Kotlin – Plugins | JetBrains
中下载了Kotlin这个Plugin,比如:
https://plugins.jetbrains.com/plugin/download?rel=true&updateId=51807
下载得到zip,解压得到lib中有:
  • kotlin-stdlib.jar
  • kotlin-stdlib-common.jar
分别导入即可
注:kotlin-stdlib-common.jar会提示无法识别,对于弹框,选择Class即可。
之后再去运行,即可正常。

转载请注明:在路上 » 【已解决】java中调用OkHttp出错:Exception in thread “main” java.lang.NoClassDefFoundError: kotlin/TypeCastException

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
19 queries in 0.106 seconds, using 9.33MB memory