2

我在尝试为 java 使用交换 Web 服务时遇到了一些问题。我越来越关注了NoSuchMethodError

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

我曾多次尝试重新安装 ews-java-api,但它并没有像我认为的那样解决问题。

我目前在 Android Studio 工作。

全栈:

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

这些是 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'
}

这是我目前正在测试的 onCreate:

@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();
    }


}
4

2 回答 2

0

尝试添加

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

在你的 build.gradle 文件中

于 2015-03-25T19:59:53.570 回答
0

下载HttpClientContext jar,然后将其包含在类路径中,然后试一试:)

于 2015-03-27T10:35:23.937 回答