1
我想通過使用簡單的Xml序列化在我的應用程序中序列化一個對象(http://simple.sourceforge.net/home.php)。我試圖序列化我的人員類,但是當我在我的設備上運行它時,我找不到我創建的xml文件。請參閱我的代碼如下:Android XML序列化
Person類:
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();
}
}
}
任何人都可以看到,我錯了?在任何人建議之前,我已經將寫入外部存儲權限添加到我的清單中。
謝謝我試過但沒有運氣 – DMC 2013-02-14 10:04:53