I'm trying to use EWS Java API for android app to connect to Exchange Server 2010 but I get an error when I used the EWS API:
Exeptions:
Could not find method javax.xml.stream.XMLOutputFactory.newInstance, referenced from method microsoft.exchange.webservices.data.EwsUtilities.formatLogMessage
VFY: unable to resolve static method 6011: Ljavax/xml/stream/XMLOutputFactory;.newInstance ()Ljavax/xml/stream/XMLOutputFactory; Could not find method javax.xml.stream.XMLStreamWriter.writeStartElement, referenced from method microsoft.exchange.webservices.data.EwsUtilities.writeTraceStartElement
Errors:
FATAL EXCEPTION: main 12-26 14:20:10.384:
java.lang.VerifyError: microsoft/exchange/webservices/data/EwsServiceXmlWriter at microsoft.exchange.webservices.data.ServiceRequestBase.emit(Unknown Source) at microsoft.exchange.webservices.data.MultiResponseServiceRequest.execute(Unknown Source)
My source code to send mail is:
ExchangeService service = new ExchangeService();
ExchangeCredentials credentials = new WebCredentials("username", "password");
service.setCredentials(credentials);
try {
uri = new URI("https://host name/ews/Exchange.asmx");
} catch (URISyntaxException e) {
e.printStackTrace();
}
service.setUrl(uri);
try {
EmailMessage msg= new EmailMessage(service);
msg.setSubject("Heloo World ");
msg.setBody(MessageBody.getMessageBodyFromText("Send using ews api in android "));
msg.getToRecipients().add("email address");
msg.send();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Thanks in advance.
Android packages the javax library that is lighter (and older) than the library used by
EWS
API. Some methods are missing.javax.xml.stream.XMLOutputFactory.newInstance
method is not available on Android.You should include in your application a newer version of the
javax
library. But some conflicts could appear..I had the same problem with commons-codec library from apache.
See how I resolved the problem here : How to resolve a library conflict (apache commons-codec)