0

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.

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
  • http://stackoverflow.com/questions/4956262/how-to-retrive-email-from-ms-exchange-server-on-android/13775447#13775447 –  Dec 31 '13 at 06:56

2 Answers2

0

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)

Community
  • 1
  • 1
nbe_42
  • 1,212
  • 1
  • 14
  • 22
  • thanks for your reply nbe_42 but i don't have problem regarding commons-codec library.But how to resolve conflict in android when i used another javax library – user3135994 Dec 26 '13 at 10:52
  • Try to do the same thing as what I did for commons-codec but for the javax library. You should add a newer version of javax inside your application. But it could be a little bit more complicated since the conflict is inside the EWS Java API. You probably must download source of the EWS API and rename the package of Javax classes (by adding a prefix for example) and then compile the library yourself. – nbe_42 Dec 26 '13 at 11:29
  • Just found this : http://stackoverflow.com/a/12384693/1646652 It explain how to do it step by step ;-) – nbe_42 Dec 26 '13 at 11:31
  • Hi when im trying to add new javax api in project it gives me error Conversion to Dalvik format failed with error 1 – user3135994 Dec 26 '13 at 13:26
  • Hard to help you if you don't send me more informations (stacktrace, ..) – nbe_42 Dec 26 '13 at 13:44
  • Hi nbe_42 I just edited the exception and error comes in stack trace so please look above and thanks for your reply – user3135994 Dec 26 '13 at 14:29
  • Sorry but I don't understand what you did. Did you tried this solution : http://stackoverflow.com/questions/9203073/problems-using-the-ews-java-api-on-android/12384693#12384693 ? At which step is the conversion error ? – nbe_42 Dec 26 '13 at 16:09
  • yes i tried that steps but when i used the jar file it giveme conversion to dalvik formate failed with error 1 – user3135994 Dec 27 '13 at 07:24
-1

You can use EWSJ, the Android port of EWS Java SDK : https://play.google.com/store/apps/details?id=com.netcompss.android_ewsj

Spawnrider
  • 1,727
  • 1
  • 19
  • 32