【发布时间】:2019-02-04 18:08:47
【问题描述】:
任何人都可以帮助解决 EWS 中的以下问题,
我收到错误 java.lang.ClassCastException:microsoft.exchange.webservices.data.property.complex.ItemAttachment 无法转换为 microsoft.exchange.webservices.data.property.complex.FileAttachment
private static void readAttachment(ExchangeService service, Folder folder, int n) {
ItemView view = new ItemView(n);
FindItemsResults<Item> findResults;
try {
findResults = service.findItems(folder.getId(), view);
System.out.println("findResults-->"+findResults.getTotalCount());
for (Item item : findResults) {
EmailMessage email;
email = EmailMessage.bind(service, item.getId(), new PropertySet(BasePropertySet.IdOnly, ItemSchema.Attachments));
System.out.println("email.getAttachments().getCount()-->"+email.getAttachments().getCount());
//email.load();
for (Attachment it : email.getAttachments()) {
System.out.println(it.getName());
FileAttachment iAttachment = (FileAttachment) it;
//iAttachment.load( "C:\\FileLocation\\" + iAttachment .getName());
}
}
} catch (ServiceLocalException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
【问题讨论】:
-
您能否更具体地说明错误消息的哪一部分让您感到困惑?在对该异常进行一些研究后,您能否告诉我们您为解决该问题所做的尝试?
-
在这一行 FileAttachment iAttachment = (FileAttachment) it;