0

我正在使用 xmlSerializer api 创建一个 xml 文件,该文件从我的数据库中导出数据。代码如下所示。我正在使用 xmlSerializer,因为我正在使用最低 API 级别 7。

        private String extractFromDB() throws IllegalArgumentException,
        IllegalStateException, IOException {


    XmlSerializer xmlSerializer = Xml.newSerializer();
    StringWriter writer = new StringWriter();
    xmlSerializer.setOutput(writer);
    // start DOCUMENT
    xmlSerializer.startDocument("UTF-8", true);

    // open tag: <root>
    xmlSerializer.startTag(null, "root");
    Cursor c = DB.getMembers();

    while (c.getPosition() < c.getCount()) {
        // open tag: <member>
        xmlSerializer.startTag(null, "member");

        xmlSerializer.attribute(null, "GR_ID", "" + c.getInt(1));

        xmlSerializer.attribute(null, "email", "" + c.getInt(2));

        xmlSerializer.attribute(null, "first_name", c.getString(3));

        xmlSerializer.attribute(null, "last_name", "" + c.getString(4));

        xmlSerializer.attribute(null, "account_nr", "" + c.getInt(5));

        xmlSerializer.attribute(null, "balance", "" + c.getDouble(6));

    }
    // end DOCUMENT
    xmlSerializer.endDocument();
    return writer.toString();
}

第二个 startTag() 抛出了一个非法状态异常。

    xmlSerializer.startTag(null, "member");

有没有人知道可能导致此错误的原因

4

0 回答 0