我正在尝试通过使用简单 Xml 序列化来序列化我的应用程序中的对象。(http://simple.sourceforge.net/home.php)。我正在尝试序列化我的人员类,但是当我在我的设备上运行它时,我找不到我创建的 xml 文件。请在下面查看我的代码:
人物类:
public class Person {
public Person() {
}
public Person(String inFirstName, String inLastName) {
SetFirstname(inFirstName);
SetLastname(inLastName);
}
private String FirstName;
public String GetFirstName() {
return FirstName;
}
public void SetFirstname(String inFirstName) {
FirstName = inFirstName;
}
private String LastName;
public String GetLastName() {
return LastName;
}
public void SetLastname(String inLastName) {
LastName = inLastName;
}
@Override
public boolean equals(Object inObject) {
if (inObject instanceof Person) {
Person inPerson = (Person) inObject;
return this.FirstName.equalsIgnoreCase(inPerson.FirstName)
&& this.LastName.equalsIgnoreCase(inPerson.LastName);
}
return false;
}
}
主要活动:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Person person1 = new Person("billy", "boontay");
File xmlFile = new File(getFilesDir().getPath() + "/Person.xml");
try {
Serializer serializer = new Persister();
serializer.write(person1, xmlFile);
} catch (Exception e) {
e.printStackTrace();
}
}
}
谁能看到我哪里出错了?在有人建议之前,我已经将写入外部存储权限添加到我的清单中。