Android, org.simpleframework.xml Persistence Exception, Element 'foo' is already used

两盒软妹~` 提交于 2019-11-30 23:32:30

问题


I am using the org.simpleframework.xml to handle some xml tasks for an android application and am running into the following error which I cannot figure out.

org.simpleframework.xml.core.PersistenceException: Element 'album' is already used with @org.simpleframework.xml.ElementList(inline=false, name=album, entry=, data=false, empty=true, required=true, type=void) on field 'albums' private java.util.List us.blah.sonar.xsd.simple.AlbumList.albums at line 5
at org.simpleframework.xml.core.Variable$Adapter.read(Variable.java:484)
at org.simpleframework.xml.core.Composite.readVariable(Composite.java:613)
at org.simpleframework.xml.core.Composite.readInstance(Composite.java:573)

Here is a sample of the XML I'm trying to unmarshall:

<albumList> 
    <album id="3985" parent="3301" title="Bob Dylan - The Reissue Series Sampler" album="Bob Dylan - The Reissue Series Sampler" artist="48 - Masked and Anonymous [BSO] (2003)" isDir="true" created="2011-12-09T11:52:12"/> 
    <album id="3986" parent="3301" title="Soundtrack - Masked & Anonymous" album="Soundtrack - Masked & Anonymous" artist="48 - Masked and Anonymous [BSO] (2003)" isDir="true" coverArt="3986" created="2011-12-09T11:52:13"/> 
    <album id="10542" parent="145" title="A Perfect Circle" album="Acoustica" artist="A Perfect Circle" isDir="true" created="2011-12-09T12:01:52"/> 
</albumList>

And here are the POJOs I created and annotated:

@Root
public class AlbumList {

    @ElementList(name="album")
    private List<Child> albums;

    public List<Child> getAlbums() {
        return albums;
    }

}

public class Child {
    @Attribute
    private String id;

    @Attribute(required=false)
    private String parent;

    @Attribute
    private boolean isDir;

    @Attribute
    private String title;

    @Attribute(required=false)
    private String album;

    @Attribute(required=false)
    private String artist;

    @Attribute(required=false)
    private int track;

    @Attribute(required=false)
    private int year;

    @Attribute(required=false)
    private String genre;

    @Attribute(required=false)
    private String coverArt;

    @Attribute(required=false)
    private long size;

    @Attribute(required=false)
    private String contentType;

    @Attribute(required=false)
    private String suffix;

    @Attribute(required=false)
    private String transcodedContentType;

    @Attribute(required=false)
    private String transcodedSuffix;

    @Attribute(required=false)
    private int duration;

    @Attribute(required=false)
    private int bitRate;

    @Attribute(required=false)
    private String path;

    @Attribute(required=false)
    private boolean isVideo;

    @Attribute(required=false)
    private String userRating;

    @Attribute(required=false)
    private double averageRating;

    @Attribute(required=false)
    private int discNumber;

    @Attribute(required=false)
    private Date created;

    @Attribute(required=false)
    private Date starred;

    @Attribute(required=false)
    private String albumId;

    @Attribute(required=false)
    private String artistId;

    @Attribute(required=false)
    private MediaType type;
}

Can anyone lead me in the right direction on how I can fix the issue, or what exactly this error message means? Is it because the XML element is named album and there is an attribute also named album?


回答1:


Try to annotate your AlbumList class this way:

@Root
public class AlbumList {
    @ElementList(entry="album", inline=true)
    private List<Child> albums;

    public List<Child> getAlbums() {
        return albums;
    }
}


来源:https://stackoverflow.com/questions/14474368/android-org-simpleframework-xml-persistence-exception-element-foo-is-already

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!