2016-09-28 74 views
0

我有以下幾點:DataSource和ByteArrayDataSource不兼容?

InputStream imageStream = classLoader.getResourceAsStream("email/logo.png"); 
DataSource fds = new ByteArrayDataSource(IOUtils.toByteArray(imageStream), "image/png"); 

會拋出我的錯誤:我在做什麼錯在這裏

Error:(65, 30) java: incompatible types: javax.mail.util.ByteArrayDataSource cannot be converted to org.apache.poi.poifs.nio.DataSource
Error:(66, 44) java: no suitable constructor found for DataHandler(org.apache.poi.poifs.nio.DataSource) constructor javax.activation.DataHandler.DataHandler(javax.activation.DataSource) is not applicable (argument mismatch; org.apache.poi.poifs.nio.DataSource cannot be converted to javax.activation.DataSource) constructor javax.activation.DataHandler.DataHandler(java.net.URL) is not applicable (argument mismatch; org.apache.poi.poifs.nio.DataSource cannot be converted to java.net.URL)

+2

我們不知道你在努力達到什麼目標,這很難幫助你。你確定你真的想要使用'org.apache.poi.poifs.nio.DataSource'嗎?也許你真的想'javax.activation.DataSource'來代替? –

+0

@JonSkeet,就是這樣! – uksz

回答

1

很可能你有錯誤的進口。 您正試圖將javax.mail.util.ByteArrayDataSource轉換成org.apache.poi.poifs.nio.DataSource。檢查你的進口。