您好我正在尝试为xml文件编写创建/更新但是当我尝试这样做时没有任何反应。我得到E / Surface:getSlotFromBufferLocked:未知缓冲区:0xb4097390但如果相关则不要。
我的代码:
String XMLyPerson = "";
try {
XMLyPerson = createXMLPerson(entries);
} catch (IOException e) {
e.printStackTrace();
}
try {
FileOutputStream fos = openFileOutput("exml.xml", Context.MODE_PRIVATE);
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fos);
outputStreamWriter.write(XMLyPerson);
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
xml方法
public static String createXMLPerson(List<Entry> list) throws IllegalArgumentException, IllegalStateException, IOException
{
XmlSerializer xmlSerializer = Xml.newSerializer();
StringWriter stringWriter = new StringWriter();
xmlSerializer.setOutput(stringWriter);
xmlSerializer.startDocument("UTF-8", true);
xmlSerializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
xmlSerializer.startTag(ns, "entries");
for (Entry entry: list) {
xmlSerializer.startTag(ns, "entry");
xmlSerializer.startTag(ns, "title");
xmlSerializer.text(entry.getTitle());
xmlSerializer.endTag(ns, "title");
for (Person p : entry.getVeiwers()) {
xmlSerializer.startTag(ns, "reader");
xmlSerializer.text(p.getName());
xmlSerializer.endTag(ns, "reader");
}
xmlSerializer.endTag(ns, "entry");
}
xmlSerializer.endTag(ns,"entries");
xmlSerializer.endDocument();
return stringWriter.toString();
}