Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I try to use Okhttp and Scarlet library but when I run project this exception throws.
how can I fix it? I search about it and I found out that the version of https is not the same in different library I added to my maven.in my maven dependency i see okhttp-4.9.1.jar and I do NOT know how i can change the version of that.
please help me ...
Exception in thread "main" java.lang.NoSuchFieldError: Companion
at okhttp3.internal.Util.<clinit>(Util.kt:71)
at okhttp3.OkHttpClient.<clinit>(OkHttpClient.kt:1073)
at crypto.Main.main(Main.java:16)
my pom.xml file :
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.cripto</groupId>
<artifactId>crypto</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.tinder.scarlet</groupId>
<artifactId>websocket-okhttp</artifactId>
<version>0.1.12</version>
</dependency>
<dependency>
<groupId>com.tinder.scarlet</groupId>
<artifactId>scarlet</artifactId>
<version>0.1.12</version>
</dependency>
<dependency>
<groupId>com.tinder.scarlet</groupId>
<artifactId>message-adapter-gson</artifactId>
<version>0.1.12</version>
</dependency>
</dependencies>
</project>
public static String Url = "wss://stream.binance.com:9443" ;
public static void main(String[] args) {
// TODO Auto-generated method stub
OkHttpClient client = new OkHttpClient() ;
System.out.println(client) ;
Scarlet scarlet = new Scarlet.Builder()
.webSocketFactory(OkHttpClientUtils.newWebSocketFactory(client,Url))
.addMessageAdapterFactory(new GsonMessageAdapter.Factory())
//.addStreamAdapterFactory(new RxJava2StreamAdapterFactory())
.build() ;
To view where the okhttp dependency is coming from please run the below command this will display the dependency in a tree format
mvn dependency:tree
Once you figure out where the dependency is populated from, you can exclude(How to exclude dependency in a Maven plugin?) okhttp from there, and add your required version.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.