Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java, okhttp, I get these exception: java.lang.NoClassDefFoundError: okio/Buffer, without module not

I use java 17 and okhttp-4.9.3. The call is:

OkHttpClient httpClient = new OkHttpClient.Builder().build();

Running the program, i get the exception:

Exception in thread "ReadStationsThread" java.lang.NoClassDefFoundError: okio/Buffer
at [email protected]/okhttp3.ResponseBody$Companion.create(ResponseBody.kt:248)
at [email protected]/okhttp3.ResponseBody$Companion.create$default(ResponseBody.kt:247)
at [email protected]/okhttp3.internal.Util.\<clinit\>(Util.kt:65)

The program can be build without error. I use gradle with these dependencies:

implementation ':okhttp-4.9.3'
implementation ':okio-3.3.0'
implementation ':okio-jvm-3.3.0'
implementation ':kotlin-stdlib-1.8.21'

in the module-info.java is these:

requires okhttp3; 
requires okio; 
requires kotlin.stdlib;

running the program, calls the exception. When i remove the mdule-info.java file, also running the program without modules, it works without problems. Anny idea what the module-info misses?

like image 740
Thomas Avatar asked May 01 '26 00:05

Thomas


1 Answers

What worked for me was this version combination:

  • okio-3.5.0
  • okio-jvm-3.5.0
  • okhttp-4.11.0
  • kotlin-stdlib-1.6.20
like image 137
Dorad Avatar answered May 03 '26 16:05

Dorad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!