Java 使用JDom2在Android上编写XML文件

Java 使用JDom2在Android上编写XML文件,java,android,xml,jdom,Java,Android,Xml,Jdom,我正在尝试将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.Main

我正在尝试将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();
    }
}

你经历过这一切吗


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

我现在遇到另一个错误-打开跟踪文件时出错:没有这样的文件或目录您知道问题出在哪里吗?好的,谢谢您回答我的第一个问题:)。