kotlin/TypeCastException when trying to create OkHttpClient object

Mouamle Hasan picture Mouamle Hasan · Jul 27, 2018 · Viewed 13.4k times · Source

When i try to create a new OkHttpClient object an Exception get thrown

I'm using OkHttp 3.11.0 and OkIO 2.0.0-RC1.

Exception in thread "main" java.lang.NoClassDefFoundError: kotlin/TypeCastException at okhttp3.ResponseBody.create(ResponseBody.java:210) at okhttp3.internal.Util.(Util.java:60) at okhttp3.OkHttpClient.(OkHttpClient.java:123) at p12.Main.main(Main.java:8) 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:349) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 4 more

Answer

Jesse Wilson picture Jesse Wilson · Jul 28, 2018

Did you add the kotlin stdlib and stdlib-common dependencies to your build? Looks like they're absent.