SimpleXMLを使用したAndroid開発の実験を始めたばかりで、問題が発生するまではかなりうまくいっていると思いました。以下のコードは、次の例外を生成します
W / System.err(665):org.simpleframework.xml.core.ConstructorException:内部クラスを構築できません
私は内部クラスに関する質問を調べて、なぜそれらを使用するのか理解していると思います(私のものは必ずしも意図的ではありませんでした)が、使用を避けるためにコードを動かしたにもかかわらず、私はまだ少し立ち往生していて、助けていただければ幸いです。
ソースコード:
public class InCaseOfEmergencyMedAlertAllergiesActivity extends Activity {
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
Serializer serializer = new Persister();
InputStream xmlstream = this.getResources().openRawResource(R.raw.sample_data_allergies);
try {
medalertdata allergyObject = serializer.read(medalertdata.class, xmlstream);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
setContentView(R.layout.allergies);
}
@Root
public class medalertdata {
@ElementList
private List<allergy> allergyList;
public List getAllergies() {
return allergyList;
}
}
@Root
public class allergy{
@Element
private String to;
@Element
private Boolean medical;
@Element
private String notes;
public allergy(String to, Boolean medical, String notes){
this.to = to;
this.medical = medical;
this.notes = notes;
}
public String getTo() {
return to;
}
public Boolean getMedical() {
return medical;
}
public String getNotes() {
return notes;
}
}
}
参照されるXMLファイルは次のように構造化されています。
<?xml version="1.0" encoding="ISO-8859-1"?>
<medalertdata>
<allergy>
<to>Penicillin</to>
<medical>true</medical>
<notes></notes>
</allergy>
<allergy>
<to>Bee Stings</to>
<medical>false</medical>
<notes>Sample</notes>
</allergy>
</medalertdata>
SimpleXMLクラスに注釈を付ける方法、またはそれらを読み込もうとしている場所に問題がありますか?ありがとう!