简体   繁体   English

EWS-Java-API-EmailMessage.send到java.lang.NullPointerException:format == null

[英]EWS-Java-API - EmailMessage.send into java.lang.NullPointerException: format == null

I want to use the EWS-Java-API for my android application. 我想为我的Android应用程序使用EWS-Java-API。 The application requires a login to get programmatically access to the microsoft exchange server (eg calendar meetings, email, meeting rooms, and much more). 该应用程序需要登录名才能以编程方式访问Microsoft Exchange服务器(例如,日历会议,电子邮件,会议室等)。

At this point almost the entire question is edited, just in case to show the situation so far. 此时,几乎所有问题都已编辑,以防万一显示目前的情况。

I try to get connected to an exchange version 15.0.11 with the url ("https ://yourserver/EWS/Exchange.asmx") 我尝试使用URL(“ https://yourserver/EWS/Exchange.asmx”)连接到Exchange版本15.0.11。

Build gradle file: 构建gradle文件:

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
useLibrary 'org.apache.http.legacy'

defaultConfig {        
    minSdkVersion 18
    targetSdkVersion 22
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
}

packagingOptions {        
    exclude 'META-INF/DEPENDENCIES.txt'
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/dependencies.txt'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/license.txt'
    exclude 'META-INF/LGPL2.1'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/notice.txt'
} [...] }

dependencies {
     compile fileTree(include: ['*.jar'], dir: 'libs')
     testCompile 'junit:junit:4.12'
     compile 'com.android.support:appcompat-v7:23.2.1'
     compile 'com.android.support:design:23.3.0'
     compile 'com.google.android.gms:play-services:6.5.87'
     compile 'org.altbeacon:android-beacon-library:2.7.1'
     compile 'org.greenrobot:eventbus:3.0.0'
     compile files('libs/jcifs-1.3.15.jar')
     compile files('libs/commons-logging-1.1.1.jar')
     compile files('libs/commons-codec-1.4.jar')
     compile files('libs/commons-httpclient-3.1.jar')
     compile 'com.microsoft.ews-java-api:ews-java-api:2.0' }

This will cause into this error message 这将导致此错误消息

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

Line: 线:

ExchangeService service = new ExchangeService();      

At this point i tested this ews libary "github.com/faisons/EWS-For-Android". 在这一点上,我测试了这个ews库“ github.com/faisons/EWS-For-Android”。

 compile files('libs/ews.jar')

This is almost working. 这几乎可以正常工作。 Iam able to start the application and set up the ExchangeService. 我可以启动应用程序并设置ExchangeService。

 Thread thread = new Thread(new Runnable()
    {
        @Override
        public void run()
        {
            try
            {
               ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
               ExchangeCredentials credentials = new WebCredentials(myuser, mypw);
               service.setCredentials(credentials);
               service.setUrl(new URI("https://exchmail.yourserver.com/EWS/Exchange.asmx"));
               EmailMessage message = new EmailMessage(service);
               EmailAddress from = new EmailAddress(myemail);
               message.setSender(from);                  
               message.getToRecipients().add(anotherEmail);
               message.setSubject("Much wow - such message");
               MessageBody messageBody = new MessageBody();
               messageBody.setText("text here");
               message.setBody(messageBody);
               message.send();

            } 
            catch (Exception e)
            {
                Log.e(TAG, "message", e);
            }
        }
    });

    thread.start();

The error now is: 现在的错误是:

java.lang.NullPointerException: format == null
    at java.lang.String.format(String.java:1799)
at java.lang.String.format(String.java:1777)
    at java.lang.String.format(String.java:1799)
    at microsoft.exchange.webservices.data.ServiceRequestBase.getEwsHttpWebResponse(ServiceRequestBase.java:936)
at microsoft.exchange.webservices.data.ServiceRequestBase.validateAndEmitRequest(ServiceRequestBase.java:821)
at microsoft.exchange.webservices.data.SimpleServiceRequestBase.internalExecute(SimpleServiceRequestBase.java:46)
at microsoft.exchange.webservices.data.MultiResponseServiceRequest.execute(MultiResponseServiceRequest.java:143)
at microsoft.exchange.webservices.data.ExchangeService.internalCreateItems(ExchangeService.java:463)
at microsoft.exchange.webservices.data.ExchangeService.createItem(ExchangeService.java:534)
at microsoft.exchange.webservices.data.Item.internalCreate(Item.java:215)
at microsoft.exchange.webservices.data.EmailMessage.internalSend(EmailMessage.java:125)

Iam confused how to get the api working. Iam困惑了如何使api工作。 If somebody knows another way to get access any hint is welcome! 如果有人知道另一种访问方式,欢迎任何提示!

Greeting! 问候! I have good news, it works! 我有个好消息,它行得通! Iam not sure if this is the perfect way, but i am able to send an Email 我不确定这是否是完美的方法,但是我可以发送电子邮件

First of all make sure that you have the permissions declared in the manifes file: 首先,请确保您具有在清单文件中声明的权限:

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

This is my Build.gradle file: 这是我的Build.gradle文件:

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
useLibrary 'org.apache.http.legacy'      // <---------------------

defaultConfig {
    applicationId "your application id"
    minSdkVersion 18
    targetSdkVersion 22
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
}

packagingOptions {
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/DEPENDENCIES.txt'
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/dependencies.txt'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/license.txt'
    exclude 'META-INF/LGPL2.1'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/notice.txt'
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:design:23.3.0
compile files('libs/ews-android-api.jar')    // <---------------------
compile 'joda-time:joda-time:2.8'}           // <---------------------

You can get the ews-android-api under this link: https://github.com/alipov/ews-android-api 您可以在以下链接下获取ews-android-api: https : //github.com/alipov/ews-android-api

Just follow the building instructions to create the jar file. 只需按照构建说明创建jar文件即可。

This is the basic command line for sending an email (run this as async task or in a new thread): 这是发送电子邮件的基本命令行(作为异步任务或在新线程中运行):

                ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
                ExchangeCredentials credentials = new WebCredentials("user", "pw");
                service.setCredentials(credentials);
                service.setUrl(new URI("https:// s e r v e r /ews/exchange.asmx"));                    
                EmailAddress mEmail = new EmailAddress("your email / test email");

                EmailMessage message = new EmailMessage(service);
                message.getToRecipients().add(mEmail);
                message.setFrom(mEmail);
                message.setSubject("Hello world!");
                message.setBody(MessageBody.getMessageBodyFromText("Sent using the EWS Android API."));
                message.send();

You can check your credentials with the EWSEditor. 您可以使用EWSEditor检查您的凭证。 Shout-out to DevilGeek and Alipov. 向DevilGeek和Alipov大喊大叫。

If something is not clear feel free to ask. 如果不清楚,请随时询问。

Kind regards! 亲切的问候!

EDIT: It seems to be working with almost everything. 编辑:似乎与几乎所有工作。 You do not need Office 365 in particular. 您特别不需要Office 365。 For example iam able to call "service.getRoomLists();" 例如,iam可以调用“ service.getRoomLists();” aswell. 以及。

Did you add the apache legacy lines into your gradle build? 您是否将apache旧代码行添加到了gradle版本中?

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"
    useLibrary 'org.apache.http.legacy'
    ...
}

See this for more info: http://developer.android.com/about/versions/marshmallow/android-6.0-changes.html#behavior-apache-http-client 看到更多信息: http : //developer.android.com/about/versions/marshmallow/android-6.0-changes.html#behavior-apache-http-client

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM