Note that there are some explanatory texts on larger screens.

plurals
  1. POSimple-framework XML deserializing
    primarykey
    data
    text
    <p>If I alter my Data.xml file to now contain two branches instead of one how do I go about catching the objects in an array?</p> <p>Current MainActivity.java file:</p> <pre><code> try { Serializer serializer = new Persister(); AssetManager assetManager = getAssets(); InputStream inputStream = assetManager.open("data.xml"); Data d = serializer.read(Data.class, inputStream); System.out.println(d.getPokemon()); } catch (Exception e) { e.printStackTrace(); } </code></pre> <p>Current Data.java file:</p> <pre><code>@Root(name="Data") public class Data { @Element(name="pkmn") private Pokemon pokemon; public Pokemon getPokemon() { return pokemon; } } </code></pre> <p>Current Pokemon.java file:</p> <pre><code>public class Pokemon implements Serializable{ @Element(name="nm") private String name; @Element(name="tp") private String type; @Element(name="ablt") private String abilities; @Element(name="wkns") private String weakness; @Element(name="img") private String image; public Pokemon(){} public Pokemon(String n, String t, String a, String w, String i){ name = n; type = t; abilities = a; weakness = w; image = i; } public String toString() {...} </code></pre> <p>Current Data.xml file:</p> <pre><code>&lt;?xml version = "1.0" encoding = "utf-8" ?&gt; &lt;Data&gt; &lt;pkmn&gt; &lt;nm&gt;Beedrill&lt;/nm&gt; &lt;tp&gt;bug&lt;/tp&gt; &lt;ablt&gt;swarm&lt;/ablt&gt; &lt;wkns&gt;fire&lt;/wkns&gt; &lt;img&gt;beedrill&lt;/img&gt; &lt;/pkmn&gt; &lt;Data&gt; </code></pre> <p>New Data.xml file:</p> <pre><code>&lt;?xml version = "1.0" encoding = "utf-8" ?&gt; &lt;Data&gt; &lt;pkmn&gt; &lt;nm&gt;Beedrill&lt;/nm&gt; &lt;tp&gt;bug&lt;/tp&gt; &lt;ablt&gt;swarm&lt;/ablt&gt; &lt;wkns&gt;fire&lt;/wkns&gt; &lt;img&gt;beedrill&lt;/img&gt; &lt;/pkmn&gt; &lt;pkmn&gt; &lt;nm&gt;Blastoise&lt;/nm&gt; &lt;tp&gt;water&lt;/tp&gt; &lt;ablt&gt;torrent&lt;/ablt&gt; &lt;wkns&gt;electric&lt;/wkns&gt; &lt;img&gt;blastoise&lt;/img&gt; &lt;/pkmn&gt; &lt;/Data&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload