Closed GreenLava786 closed 1 year ago
The error message indicates that there's an issue with the version of org.apache.httpcomponents:httpclient that you are using. The Twilio SDK depends on this library, and it appears that the version of this library you are using doesn't have the AllowAllHostnameVerifier.INSTANCE field, which the SDK is trying to use.
The simplest way to resolve this issue would be to ensure that you're using a version of org.apache.httpcomponents:httpclient that's compatible with the Twilio SDK. According to the Twilio SDK's build.gradle file, it depends on version 4.5.13 of this library.
If you're using Gradle, you can specify this version in your build.gradle file like so:
groovy
**dependencies { // Other dependencies...
implementation 'org.apache.httpcomponents:httpclient:4.5.13'
}**
If you're using Maven, you can specify this version in your pom.xml file like so:
xml
**
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.13</version>
</dependency>
**
You should also make sure that there are no other libraries in your classpath that are including different versions of the httpclient library, as this could also cause conflicts.
If the problem persists, you might want to consider downgrading your Twilio SDK to a version that's compatible with your current httpclient library. However, you'd need to check the Twilio SDK's documentation to find out which version this would be.
Hope this helps!
Hey @DanielErnestoThompson, Thank you for answer this question. I checked in my project it is using '4.5.13' version for httpClient. I'm still getting this error. Below I put the full error. Please, let me know if anything I'm missing.
Exception in thread "main" java.lang.NoSuchFieldError: INSTANCE
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.<clinit>(SSLConnectionSocketFactory.java:151)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.getDefaultRegistry(PoolingHttpClientConnectionManager.java:116)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:123)
at com.twilio.http.NetworkHttpClient.<init>(NetworkHttpClient.java:70)
at com.twilio.http.NetworkHttpClient.<init>(NetworkHttpClient.java:45)
at com.twilio.http.NetworkHttpClient.<init>(NetworkHttpClient.java:36)
at com.twilio.http.TwilioRestClient$Builder.build(TwilioRestClient.java:143)
at com.twilio.Twilio.buildRestClient(Twilio.java:202)
at com.twilio.Twilio.getRestClient(Twilio.java:174)
at com.twilio.base.Creator.create(Creator.java:40)
at com.example.demomaskedcall.Example.main(Example.java:29)
I did the below code:
Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
Call call = Call.creator(
new com.twilio.type.PhoneNumber("MY_PHONE_NUMBER"),
new com.twilio.type.PhoneNumber("TWILIO_PHONE_NUMBER"),
URI.create("http://demo.twilio.com/docs/voice.xml"))
.create();
System.out.println("Masked Call: " + call.getSid());
I have made a custom API call for Twilio Api's using Retrofit to send SMS and receive an SMS list." You can check this at: https://github.com/waseem-i7/Contact-App. If you don't understand anything, please let me know.
Hi @GreenLava786 and shweta-7span, I tested the code pasted in the thread, with twilio-java version 9.6.0 and java version 11.0.19 and this is working for me. Here is the configuration details for my project
<artifactId>httpclient</artifactId>
<version>4.5.13</version>
and
<artifactId>httpcore</artifactId>
<version>4.4.13</version>
Hi @GreenLava786 and @shweta-7span Are you trying to run this inside your android application? if yes you might find the below information helpful The twilio-java library is not intended for use in Android applications. If you were to use it within an Android application you would expose your Application SID and Auth Token. If a malicious user were to discover this, they could abuse your account.
Instead, we recommend that you set up a server from which you send the messages and make requests to that server from your Android application. Check out this post on sending SMS messages from your Android app for more details.
Yes, I made the "Example.Java" class inside the app folder of android app project and run it with "Coverage". I will do from the above blog which you shared.
Thank you @AsabuHere :smiley:
I got the same error with the twilio-java version 9.7.0, with 'httpclient', version: '4.5.2' and 'httpcore', version: '4.4.4' The error log is
java.lang.NoSuchMethodError: org.apache.http.impl.client.DefaultRedirectStrategy.<init>([Ljava/lang/String;)V
at com.twilio.http.HttpClient.<init>(HttpClient.java:35)
at com.twilio.http.NetworkHttpClient.<init>(NetworkHttpClient.java:54)
at com.twilio.http.NetworkHttpClient.<init>(NetworkHttpClient.java:45)
at com.twilio.http.NetworkHttpClient.<init>(NetworkHttpClient.java:36)
at com.twilio.http.TwilioRestClient$Builder.build(TwilioRestClient.java:143)
the issue got fixed when I changed the Http client version to version: '4.5.12' , (Only the client version) and I'm using java version 8, should I update the HTTP core version too?
Hi @GreenLava786, Closing this issue since twilio-java library is not intended for use in Android applications.
@sharunthomas Please open a new issue with the details of the environment and use case to track this
Issue Summary
Code Snippet
paste exception/log here