0
왜 "null"을 반환합니까?단순 XML 비 직렬화
package com.example.pokemon;
import java.io.Serializable;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Root;
@Root(name="Data", strict=false)
public class Data implements Serializable {
public Data() {}
@Element(name = "nm", required=false)
private String nm;
public String gtNm(){
return nm;
}
@Element(name = "tp", required=false)
private String tp;
public String gtTp(){
return tp;
}
}
인 data.xml : 그것은 ...
Data.java을 "Beedrill & 버그"를 반환해야
<?xml version = "1.0" encoding = "utf-8" ?>
<Data>
<Pokemon>
<nm>Beedrill</nm>
<tp>bug</tp>
<ablt>swarm</ablt>
<wkns>fire</wkns>
<img>beedrill</img>
</Pokemon>
</Data>
MainActivity.java :
try {
Serializer serializer = new Persister();
AssetManager assetManager = getAssets();
InputStream inputStream = assetManager.open("data.xml");
Data d = serializer.read(Data.class, inputStream);
System.out.println("[JOE]: It worked! "+d.gtNm());
System.out.println("[JOE]: It worked! "+d.gtTp());
}
catch (Exception e) {
e.printStackTrace();
System.out.println("[JOE]: error! "+e.getMessage());
}
로그 캣 :
귀하의 XML 트리가3210