문제

I am trying to use JDom version 2.0.5 with my android sdk. When I try to run the app, it always crashes, where as, if I make a normal java application it works fine. I am trying to write an XML file to the src folder. Here is the logcat logs:

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

and Here is my code:

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();
    }
}
도움이 되었습니까?

해결책

Have you gone through this; https://github.com/hunterhacker/jdom/wiki/JDOM2-and-Android. ?

Specifically, is the JDOM jar inthe libs folder of your android project?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top