0

我正在尝试将 JDom 版本 2.0.5 与我的 android sdk 一起使用。当我尝试运行该应用程序时,它总是崩溃,如果我制作一个普通的 Java 应用程序,它就可以正常工作。我正在尝试将 XML 文件写入 src 文件夹。这是 logcat 日志:

08-04 11:36:53.126: E/dalvikvm(755): Could not find class 'org.jdom2.Document', referenced     from method com.example.touchsensor.MainActivity.writeXML

这是我的代码:

package com.example.touchsensor;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import java.io.*;
import org.jdom2.*;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    writeXML();


}




private static void writeXML() {

    try{
    Document doc = new Document();

    Element theRoot = new Element("tvshows");
    doc.setRootElement(theRoot);

    Element show = new Element("show");
    Element name = new Element("show");
    name.setAttribute("show_id", "show_001");

    name.addContent(new Text("Life On mars"));

    Element network = new Element("network");
    network.setAttribute("country", "US");

    network.addContent(new Text("ABC"));

    show.addContent(name);
    show.addContent(network);

    theRoot.addContent(show);

    // - -



    Element show2 = new Element("show");
    Element name2 = new Element("show");
    name2.setAttribute("show_id", "show_002");

    name2.addContent(new Text("Life On mars"));

    Element network2 = new Element("network");
    network2.setAttribute("country", "US");

    network2.addContent(new Text("ABC"));

    show2.addContent(name2);
    show2.addContent(network2);

    theRoot.addContent(show2);

    XMLOutputter xmlOutput = new XMLOutputter(Format.getPrettyFormat());
    xmlOutput.output(doc, new FileOutputStream(new File("./src/jdomMade.xml")));
    }catch(Exception e){
        e.printStackTrace();
    }
}
4

1 回答 1

1

你经历过这个吗?https://github.com/hunterhacker/jdom/wiki/JDOM2-and-Android。?

具体来说,JDOM jar 是否在libs您的 android 项目的文件夹中?

于 2013-08-04T13:08:10.030 回答