SimpleXML构造函数异常-无法创建内部类 [英] SimpleXML Constructor Exception - Can not create Inner Class
问题描述
我刚刚开始尝试使用SimpleXML进行Android开发,并认为在我遇到麻烦之前,它运行得很好.以下代码产生
I'm just beginning to experiment with Android Development with SimpleXML and thought it was going quite well until I hit a snag. The code below produces an exception of
W/System.err(665):org.simpleframework.xml.core.ConstructorException:无法构造内部类
W/System.err(665): org.simpleframework.xml.core.ConstructorException: Can not construct inner class
我已经遍历了有关内部类的问题,并认为我理解您为什么要使用它们(不是我的事情是故意的),但是尽管我不断修改代码以尝试避免使用,但仍然有些卡住并且感谢您的帮助.
I've looked through the questions on inner classes and think I understand why you would use them (not that mine was necessarily intentional) but despite moving my code round to try and avoid usage I'm still a little stuck and would appreciate any help.
源代码:
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文件的结构为:
With the XML file referenced structured as:
<?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类或试图在何处读取它们的问题?谢谢!
Is the problem with how I have annotated the SimpleXML classes or where I am trying to read them? Thanks!
推荐答案
尝试从allergy
类中删除@Root
.
还:您是否在单独的文件中分别拥有这两个类:allergy.java和badgeertdata.java?
Also: do you have this two classes each in it's separate file: allergy.java and medalertdata.java?
这篇关于SimpleXML构造函数异常-无法创建内部类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!