0
我被困在下面的這個錯誤中。 這是XML響應在改裝中使用SimpleXMLConverter將XML響應轉換爲POJO
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
<channel>
<title>SnagFilms Recent Additions</title>
<item>
<media:title>Sink or Swim - Trailer</media:title>
<title>Sink or Swim - Trailer</title>
<media:description> Jon Bowermaster's documentary on a learn-to-swim camp for third graders and their moms on the island-nation of the Maldives
</media:description>
<media:credit role="Director" scheme="urn:ebu">Jon Bowermaster</media:credit>
<media:thumbnail type="landscape" url="http://snagfilms-a.akamaihd.net/sinkorswim-video.jpg"/>
<media:content duration="117" height="323" width="500"/>
<media:rights status="official"/>
<media:player height="323" url="http://embed.snagfilms.com/embed/player?filmId=00000158-b20c-d8f9-affd-b32ce8700000" width="500"/>
</item>
</channel>
</rss>
這是用我的REST調用的代碼可觀察到的
rx.Observable<Rss> videosObservable = RetrofitHelper.createListObs();
videosObservable.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<Rss>() {
@Override
public void onCompleted() {
Log.d(TAG, "onCompleted: ");
}
@Override
public void onError(Throwable e) {
Log.d(TAG, "onError: " + e.toString());
}
@Override
public void onNext(Rss rss) {
Log.d(TAG, "onNext: ");
}
});
這是我得到
onError: java.lang.RuntimeException: org.simpleframework.xml.core.ElementException: Element 'item' does not have a match in class com.example.singh.xmlParser.model.Channel at line 12
我的RSS類錯誤
@Root(strict = false)
public class Rss {
public Channel getChannel() {
return channel;
}
@Element
public Channel channel;
}
我的頻道類
@Element
public class Channel {
@Element(name = "title")
String title;
@ElementList
List<Item> items;
public List getItems(){
return items;
}
}
我需要幫助在Java中爲XML創建正確的POJO。如果有人能夠按照給定的格式製作所有的POJO,我將不勝感激。響應鏈接http://www.snagfilms.com/feeds/。轉換器文檔http://simple.sourceforge.net/home.php
請分享您的RetrofitHelper課程。 –