Re: [Simple-support] ValueRequiredException
Brought to you by:
niallg
|
From: Niall G. <gal...@ya...> - 2011-07-21 09:50:36
|
Hi, Your annotations look wrong, @Element does not work with classes, it works only with fields and methods. Instead use @Root for classes. Also, the @ElementList needs to have the name of "enemies" not "enemy". Take a look at the tutorial http://simple.sourceforge.net/download/stream/doc/tutorial/tutorial.php. Regards, Niall --- On Wed, 20/7/11, Crundy 12 <cru...@gm...> wrote: From: Crundy 12 <cru...@gm...> Subject: [Simple-support] ValueRequiredException To: sim...@li... Received: Wednesday, 20 July, 2011, 6:28 AM Hi all,I'm sure I'm doing something silly, but I can't for the life of me get Simple working. I'm trying to read in this XML from my Android assets folder: <?xml version="1.0" encoding="utf-8"?> <enemies> <enemy type="1" name="Enemy1"> <spritesheet>sheet2.png</spritesheet> <viewtilesfront>1</viewtilesfront> <viewtilesside>0</viewtilesside> <description> Description of enemy 1 </description> </enemy> <enemy type="2" name="Enemy2"> <spritesheet>sheet2.png</spritesheet> <viewtilesfront>1</viewtilesfront> <viewtilesside>1</viewtilesside> <description> Description of enemy 2 </description> </enemy> </enemies> So I have my two classes: Enemies.javapackage my.package.name; import java.util.List; import org.simpleframework.xml.Root; import org.simpleframework.xml.ElementList; @Root public class Enemies { @ElementList(name="enemy") private List<Enemy> enemies; public List<Enemy> getEnemies(){return this.enemies;} }: Enemy.java:package my.package.name; import org.simpleframework.xml.Element; import org.simpleframework.xml.Attribute; @Element(name="enemy") public class Enemy { @Attribute(name="type") private int type; public int getType(){return this.type;} @Attribute(name="name") private String name; public String getName(){return this.name;} @Element(name="spritesheet") private String spriteSheet; public String getSpriteSheet(){return this.spriteSheet;} @Element(name="viewtilesfront") private int viewTilesFront; public int getViewTilesFront(){return this.viewTilesFront;} @Element(name="viewtilesside") private int viewTilesSide; public int getViewTilesSide(){return this.viewTilesSide;} @Element(name="description") private String description; public String getDescription(){return this.description;}} But I always end up with: 07-20 13:22:54.981: WARN/System.err(338): org.simpleframework.xml.core.ValueRequiredException: Unable to satisfy @org.simpleframework.xml.Attribute(empty=, name=name, required=true) on field 'name' private java.lang.String my.package.name.Enemy.name for class my.package.name.Enemy at line 4 I've tried playing around with almost everything, using Root instead of element for the Enemy class, removing the name attributes from everything, no joy. I've tried using public class variables without get methods. If I just have one enemy entry under enemies and use a single Enemy object instead of the List then it works fine, I just can't seem to get ElementList working. -----Inline Attachment Follows----- ------------------------------------------------------------------------------ 10 Tips for Better Web Security Learn 10 ways to better secure your business today. Topics covered include: Web security, SSL, hacker attacks & Denial of Service (DoS), private keys, security Microsoft Exchange, secure Instant Messaging, and much more. http://www.accelacomm.com/jaw/sfnl/114/51426210/ -----Inline Attachment Follows----- _______________________________________________ Simple-support mailing list Sim...@li... https://lists.sourceforge.net/lists/listinfo/simple-support |