Exception in thread "main" java.lang.NoSuchFieldError: INSTANCE
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.<clinit>(SSLConnectionSocketFactory.java:144)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.getDefaultRegistry(PoolingHttpClientConnectionManager.java:109)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:116)
at com.twilio.http.NetworkHttpClient.<init>(NetworkHttpClient.java:58)
at com.twilio.http.TwilioRestClient$Builder.build(TwilioRestClient.java:102)
at com.twilio.Twilio.getRestClient(Twilio.java:122)
at com.twilio.base.Creator.create(Creator.java:45)
at com.systema.twilliovoicecalltest.MakePhoneCall.main(MakePhoneCall.java:33)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131)
implementation (group: "com.twilio.sdk", name: "twilio", version: "7.34.1")
{
exclude group: 'org.apache.httpcomponents' ,module:'httpclient'
exclude group: 'org.apache.httpcomponents' ,module:'httpcore'
}
implementation (group: "com.sparkjava", name: "spark-core", version: "2.7.1")
{
exclude group: 'org.apache.httpcomponents' ,module:'httpclient'
exclude group: 'org.apache.httpcomponents' ,module:'httpcore'
}
implementation (group: "org.slf4j", name: "slf4j-simple", version: "1.7.21")
{
exclude group: 'org.apache.httpcomponents' ,module:'httpclient'
exclude group: 'org.apache.httpcomponents' ,module:'httpcore'
}
>Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/ProtocolVersion
at com.twilio.http.TwilioRestClient$Builder.build(TwilioRestClient.java:102)
at com.twilio.Twilio.getRestClient(Twilio.java:122)
at com.twilio.base.Creator.create(Creator.java:45)
at com.systema.twilliovoicecalltest.MakePhoneCall.main(MakePhoneCall.java:33)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131)
Caused by: java.lang.ClassNotFoundException: org.apache.http.ProtocolVersion
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 9 more
这是我的Java代码:
public static void main(String[] args) throws URISyntaxException {
Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
String from = "+18572632XXX";
String to = "+92**********";
Call call = Call.creator(new PhoneNumber(to), new PhoneNumber(from),
new URI("http://demo.twilio.com/docs/voice.xml")).create();
System.out.println(call.getSid());
}
i已包含所有必需的库:
>implementation group: "com.twilio.sdk", name: "twilio", version: "7.34.1"</br>
>implementation group: "com.sparkjava", name: "spark-core", version: "2.7.1"</br>
>implementation group: "org.slf4j", name: "slf4j-simple", version: "1.7.21"</br>
由于我没有太多经验,请帮忙
答案 0 :(得分:1)
此处是Twilio开发人员的传播者。您已经注意到,Android使用我们的Java SDK会遇到麻烦,因为它的依赖项之一是HTTP的Apache库。不过,您要做的就是使用我们的Android SDK拨打电话。
您可以看到一个示例here,以及通过quickstart进行操作的示例。
在您的示例中,您正在使用Java SDK,这已成为应用程序中的安全问题,因为它现在已将您的帐户凭据硬编码到最终的APK中。在此blog post中,我解释了为什么这不是一个好主意。
希望这对您有所帮助。