JayTwOne
JayTwOne

Reputation: 21

OkHttp causes an NoClassDefFoundError no matter the dependency versions

I'm trying to use an API via RapidAPI to get various basketball stats. The following error points at the OkHttpClient declaration line below. I've tried adding multiple releases of Kotlin-stdlib JAR files to the project's build path (I'm using Eclipse) and get the same error running this test request. I currently have Kotlin v1.4.10 added to the build path and see the class named in the error message in the list of referenced libraries. I am also using the OkHttp v4.91 and Okio v2.7.0 libraries, as stated in the OkHttp changelog. Also, I didn't build with Maven or Gradle.

    OkHttpClient client = new OkHttpClient();
    Request request = new Request.Builder()
        .url("https://api-nba-v1.p.rapidapi.com/players/firstName/lebron")
        .get()
        .addHeader("x-rapidapi-key", rAPIKey)
        .addHeader("x-rapidapi-host", host)
        .build();

    Response response = client.newCall(request).execute();

   System.out.println(response.body().string());

Yielding this error code:

Exception in thread "main" java.lang.NoClassDefFoundError: kotlin/jvm/internal/markers/KMappedMarker
at okhttp3.internal.Util.<clinit>(Util.kt:63)
at okhttp3.OkHttpClient.<clinit>(OkHttpClient.kt:1073)
at CourtVisionary.main(CourtVisionary.java:39)

What could be causing this issue? Thanks in advance.

Edit: Fixed my own issue. I created a new project, copied and pasted my java files over. Added the JAR files, and got no error when I ran.

Upvotes: 2

Views: 1718

Answers (2)

divine
divine

Reputation: 31

I had the same problem then I added below jar in dependency then it got solved.

annotations-13.0
kotlin-stdlib-1.9.21
okhttp-5.0.0-alpha.14
okio-3.0.0-alpha.9
okio-jvm-3.9.0

Upvotes: 0

JayTwOne
JayTwOne

Reputation: 21

Fixed my own issue. I created a new project, copied and pasted my java files over. Added the JAR files, and got no error when I ran.

Upvotes: 0

Related Questions