title: Using JDom2 to write XML files on Android
body: <p>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:</p>
  
  <pre><code>08-04 11:36:53.126: E/dalvikvm(755): Could not find class 'org.jdom2.Document', referenced     from method com.example.touchsensor.MainActivity.writeXML
  </code></pre>
  
  <p>and Here is my code:</p>
  
  <pre><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();
      }
  }
  </code></pre>