ฉันต้องการใช้ RSSUtil เพื่ออ่านฟีด RSS แต่ฉันประสบปัญหากับตัวโหลดคลาส...
ข้อยกเว้นที่เกิดขึ้นคือ:
com.sun.syndication.feed.synd.SyndFeedImpl cannot be cast to com.sun.syndication.feed.synd.SyndFeedImpl
รหัสของฉันคือ:
SyndFeedImpl feed = null;
final String _CLASS_NAME = "com.liferay.portlet.rss.util.RSSUtil";
MethodKey _CONSTRUCTOR = new MethodKey(_CLASS_NAME, "getFeed", String.class);
ObjectValuePair ovp = (ObjectValuePair) PortalClassInvoker.invoke(true, _CONSTRUCTOR, url);
Class<SyndFeed> clazz = (Class<SyndFeed>) PortalClassLoaderUtil.getClassLoader().loadClass(
"com.sun.syndication.feed.synd.SyndFeedImpl");
feed = (SyndFeedImpl) ovp.getValue();
ปัญหานี้ยังได้อธิบายไว้ใน https://www.liferay.com/fr/community/forums/-/message_boards/message/15812507. พยายามทำเหมือนกันแต่ไม่ได้ผล...
ขอบคุณล่วงหน้าสำหรับความช่วยเหลือของ...
อัปเดต: ถ้าฉันใช้รหัสด้านล่าง (วิธีแก้ไขปัญหาอื่นที่ไม่มี RSSUtil):
URL feedUrl = new URL(url);
HttpURLConnection httpcon = (HttpURLConnection) feedUrl.openConnection();
SyndFeedInput input = new SyndFeedInput();
XmlReader reader = new XmlReader(httpcon);
SyndFeed feed = input.build(reader);
ข้อยกเว้นที่เกิดขึ้นคือ:
java.lang.ClassCastException: com.sun.syndication.feed.synd.impl.ConverterForAtom10 cannot be cast to com.sun.syndication.feed.synd.Converter