Reputation: 6743
This is the first time I work with OkHttp, and I want to study some basic codes first.
So this is the code, taken from here:
package com.anta40.app.okconnectiontest;
import java.io.IOException;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
public class MainClass {
public static void main(String args[]) {
OkHttpClient okcl = new OkHttpClient();
Request request = new Request.Builder()
.url("http://www.vogella.com/index.html")
.build();
okcl.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
e.printStackTrace();
}
@Override
public void onResponse(Call call, final Response response) throws IOException {
if (!response.isSuccessful()) {
throw new IOException("Unexpected code " + response);
}
else {
System.out.println("okay.....");
}
}
});
}
}
Running the code on Eclipse yields this output:
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 com.anta40.app.okconnectiontest.MainClass.main(MainClass.java:14) 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
I have OkHttp and kotlin jars in my build path:
I'm on Windows 10 64, with JDK 1.8.0_181, OkHttp 3.11, OkIo 2.1.0, kotlib-stdlib -0.6.179, kotlin-stdlib-common 1.2.71 What's wrong here?
Upvotes: 2
Views: 5630