NoSuchMethodError on ews-java-api

徘徊边缘 提交于 2019-12-11 02:49:47

问题


I'm having some issues trying to use exchange webservices for java. I'm getting following NoSuchMethodError.

java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/client/protocol/HttpClientContext;

I've tried reinstalling ews-java-api several times but it hasnt been solving the problem as i believed it would.

I'm currently working in Android Studio.

Full stack:

03-25 15:37:23.551    1875-1875/com.example.XXXXX.test E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.XXXXXX.test, PID: 1875
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/client/protocol/HttpClientContext;
        at microsoft.exchange.webservices.data.ExchangeServiceBase.initializeHttpContext(ExchangeServiceBase.java:211)
        at microsoft.exchange.webservices.data.ExchangeServiceBase.setUseDefaultCredentials(ExchangeServiceBase.java:628)
        at microsoft.exchange.webservices.data.ExchangeServiceBase.<init>(ExchangeServiceBase.java:158)
        at microsoft.exchange.webservices.data.ExchangeServiceBase.<init>(ExchangeServiceBase.java:164)
        at microsoft.exchange.webservices.data.ExchangeService.<init>(ExchangeService.java:3663)
        at com.example.XXXXXX.test.MainActivity.onCreate(MainActivity.java:25)
        at android.app.Activity.performCreate(Activity.java:5933)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
        at android.app.ActivityThread.access$800(ActivityThread.java:144)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5221)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
 Caused by: java.lang.ClassNotFoundException: Didn't find class "org.apache.http.client.protocol.HttpClientContext" on path: DexPathList[[zip file "/data/app/com.example.XXXXXXX.test-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at      microsoft.exchange.webservices.data.ExchangeServiceBase.initializeHttpContext(ExchangeServiceBase.java:211)
 at microsoft.exchange.webservices.data.ExchangeServiceBase.setUseDefaultCredentials(ExchangeServiceBase.java:628)
at microsoft.exchange.webservices.data.ExchangeServiceBase.<init>(ExchangeServiceBase.java:158)
at microsoft.exchange.webservices.data.ExchangeServiceBase.<init>(ExchangeServiceBase.java:164)
at microsoft.exchange.webservices.data.ExchangeService.<init>(ExchangeService.java:3663)
at com.example.XXXXXX.test.MainActivity.onCreate(MainActivity.java:25)
at android.app.Activity.performCreate(Activity.java:5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Suppressed: java.lang.ClassNotFoundException: org.apache.http.client.protocol.HttpClientContext
        at java.lang.Class.classForName(Native Method)
        at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
        at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
        ... 20 more
 Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

These are the dependencies in build.gradle:

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:19.0.0'
//compile 'org.apache.httpcomponents:httpclient:4.4'
//compile 'org.apache.httpcomponents:httpcore:4.3.3'
//compile 'commons-logging:commons-logging:1.2'
//compile 'joda-time:joda-time:2.7'
}

And here's the onCreate I'm currently testing:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ExchangeService service = new ExchangeService(); // this is where the error is hitting
    ExchangeCredentials credentials = new WebCredentials("user", "pw");
    service.setCredentials(credentials);

    try {
        service.setUrl(new URI("uri"));
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }

    EmailMessage msg= null;
    try {
        msg = new EmailMessage(service);
        msg.setSubject("Hello world!");
        msg.setBody(MessageBody.getMessageBodyFromText("Sent using the EWS Java API."));
        msg.getToRecipients().add("email");
        msg.send();
    } catch (Exception e) {
        e.printStackTrace();
    }


}

回答1:


Try adding

compile 'org.apache.httpcomponents:httpclient:4.4'

in your build.gradle file




回答2:


Download HttpClientContext jar, then include it in classpath and then give it a try :)



来源:https://stackoverflow.com/questions/29265299/nosuchmethoderror-on-ews-java-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!