0
import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;

import java.io.IOException;
import java.util.UUID;

public class MainActivity {

    public static void main(String[] args) {
        String accessKey = System.getenv("UPBIT_OPEN_API_ACCESS_KEY");
        String secretKey = System.getenv("UPBIT_OPEN_API_SECRET_KEY");
        String serverUrl = System.getenv("UPBIT_OPEN_API_SERVER_URL");

        Algorithm algorithm = Algorithm.HMAC256(secretKey);
        String jwtToken = JWT.create()
                .withClaim("access_key", accessKey)
                .withClaim("nonce", UUID.randomUUID().toString())
                .sign(algorithm);

        String authenticationToken = "Bearer " + jwtToken;

        try {
            HttpClient client = HttpClientBuilder.create().build();

            HttpGet request = new HttpGet(serverUrl + "/v1/accounts");
            request.setHeader("Content-Type", "application/json");
            request.addHeader("Authorization", authenticationToken);

            HttpResponse response = client.execute(request);
            HttpEntity entity = response.getEntity();

            System.out.println(EntityUtils.toString(entity, "UTF-8"));
        } catch (IOException e) {
      

  e.printStackTrace();
        }
    }

}

I try to get data about cryptocurrency from api, but the error below keeps popping up.

Exception in thread "main" java.lang.NoSuchFieldError: INSTANCE at org.apache.http.conn.ssl.SSLConnectionSocketFactory.(SSLConnectionSocketFactory.java:144) at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:955) at com.example.koin3.MainActivity.main(MainActivity.java:34)

I think libraries in dependecies or sdk is something wrong.. I tried to solve this problem for a day but I couldn't solve this problem.. my compileSdkVersion is 30 and buildToolsVersion is "29.0.3".. Is the sdk version a problem?

 dependencies {
    
            implementation 'androidx.appcompat:appcompat:1.3.0'
            implementation 'com.google.android.material:material:1.3.0'
            implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
            testImplementation 'junit:junit:4.+'
            androidTestImplementation 'androidx.test.ext:junit:1.1.2'
            androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
            implementation 'com.auth0:java-jwt:3.16.0' // for jwt
            implementation 'org.apache.httpcomponents:httpclient:4.5'
            androidTestImplementation 'androidx.test.ext:junit:1.1.2'
            implementation 'com.fasterxml.jackson.core:jackson-databind' // for jwtToken
            implementation 'com.fasterxml.jackson.core:jackson-core:2.12.1' // for jwtToken
            //noinspection GradleCompatible
            implementation fileTree(dir: 'libs', include: ['*.jar'])
        //    implementation 'com.android.support:appcompat-v7:29.1.0'
        //    implementation 'com.android.support:support-v4:30.1.0'
        //    implementation 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
        //    implementation "org.apache.httpcomponents:httpcore:4.3.2"
        
        }
Jamong25
  • 11
  • 1
  • 4
  • Does this answer your question? [HTTPClient "main" java.lang.NoSuchFieldError: INSTANCE at org.apache.http.conn.ssl.SSLConnectionSocketFactory.](https://stackoverflow.com/questions/35868242/httpclient-main-java-lang-nosuchfielderror-instance-at-org-apache-http-conn-s) – Wale Jun 20 '21 at 09:53
  • no.. I think that cannot be my answer.. I found the same error here and tried to fix it, but I couldn't fix the error... so I posted the question. – Jamong25 Jun 20 '21 at 10:06

0 Answers0