anta40
anta40

Reputation: 6743

java.lang.NoClassDefFoundError: kotlin/TypeCastException when running code using OkHttp

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: enter image description here enter image description here enter image description here

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

Answers (1)

Sivaprasad
Sivaprasad

Reputation: 151

The code worked for me with okhttp-3.9.0.jar & okio-1.13.0.jar.

Upvotes: 5

Related Questions