简体   繁体   English

ews-java-api-无法设置类的实例

[英]ews-java-api - cant set instance of class

im trying to develop ews-java-api simple program. 我正在尝试开发ews-java-api简单程序。 i am following the guide and it shows how to set an ExchangeService variable name "service". 我正在按照指南进行操作 ,它显示了如何设置ExchangeService变量名称“ service”。

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
ExchangeCredentials credentials = new WebCredentials("emailAddress", "password");
service.setCredentials(credentials);

i've made it and it's all good. 我做到了,一切都很好。

then it shows how to create a message variable class, under the title "sending a message" 然后显示在标题“发送消息”下如何创建消息变量类

EmailMessage msg= new EmailMessage(service);
msg.setSubject("Hello world!");
msg.setBody(MessageBody.getMessageBodyFromText("Sent using the EWS Java API."));
msg.getToRecipients().add("someone@contoso.com");
msg.send();

my program won't accept it. 我的程序不会接受。 i get an error: 我得到一个错误:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    Unhandled exception type Exception

    at project2.liran.main(liran.java:19)

here is my program as i wrote it: 这是我写的程序:

package project2;

import microsoft.exchange.webservices.data.core.ExchangeService;
import microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion;
import microsoft.exchange.webservices.data.core.service.item.Appointment;
import microsoft.exchange.webservices.data.core.service.item.EmailMessage;
import microsoft.exchange.webservices.data.credential.ExchangeCredentials;
import microsoft.exchange.webservices.data.credential.WebCredentials;
import java.net.*;


public class liran {
    public static void main(String[] args) {        
    ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
    ExchangeCredentials credentials = new WebCredentials("emailAddress", "password");
    service.setCredentials(credentials);
    URI uri = URI.create ("http://www.cnn.com");
    service.setUrl(uri);
    EmailMessage msg= new EmailMessage(service);
    }

}

what am i doing wrong? 我究竟做错了什么?

It is exactly as the error message states. 正是错误消息指出的状态。 In line no 19, the Checked Exception is not handled. 在第19行中,不处理Checked Exception。 The Constructor for EmailMessage has throws Exception clause and so your program must handle it. EmailMessage的构造方法具有throws Exception子句,因此您的程序必须对其进行处理。

This is the constructor: 这是构造函数:

 public EmailMessage(ExchangeService service) throws Exception {
    super(service);
  }

Reference : Github Repo 参考: Github回购

I would advise you to go with an IDE (Eclipse, Netbeans, IntelliJ IDEA) for your development. 我建议您使用IDE(Eclipse,Netbeans,IntelliJ IDEA)进行开发。

Visit Oracle's Exception Handling for more information. 有关更多信息,请访问Oracle的异常处理

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

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