简体   繁体   English

Android上的JDom:打开跟踪文件时出错:没有这样的文件或目录

[英]JDom on Android: error opening trace file: No such file or directory

I don't understand why I'm getting this error, I'm trying to write to a file, not read from it. 我不明白为什么会收到此错误,我试图写入文件,而不是读取文件。 At first I got an error because I didn't put a jar in the libs folder, now I am getting this error. 刚开始我遇到一个错误,因为我没有在libs文件夹中放一个jar,现在我收到了这个错误。 Here's my code, help would be appreciated! 这是我的代码,将不胜感激! :) :)

public class MainActivity extends Activity {

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

    setContentView(R.layout.activity_main);


    writeXML();


}




private 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("C:\\Users\\jmckay\\Desktop\\jdomMade.xml")));


    TextView tv = (TextView)findViewById(R.id.text);
    tv.setText("done");
    }catch(Exception e){
        e.printStackTrace();
    }
}

It looks like you're trying to save to a Windows file address, which you can't do from an Android device (emulated or otherwise). 似乎您正在尝试保存到Windows文件地址,而在Android设备上(模拟或其他方式)无法执行此操作。 You can use openFileOutput to get a FileOutputStream to write to a file in internal storage (specific to your app): 您可以使用openFileOutput获取FileOutputStream以写入内部存储中的文件(特定于您的应用程序):

xmlOutput.output(doc, openFileOutput(yourFilename, Context.MODE_PRIVATE));

Have a look at this developer guide on Storage Options , in particular Internal and External Storage. 请参阅有关存储选项 (特别是内部和外部存储)的开发人员指南。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android - 错误打开跟踪文件:没有这样的文件或目录 - Android - error opening trace file: No such file or directory Android E / Trace(627):打开跟踪文件时出错:没有这样的文件或目录(2) - Android E/Trace(627): error opening trace file: No such file or directory (2) Android运行时错误:打开跟踪文件时出错:没有这样的文件或目录(2) - Android runtime error: error opening trace file: No such file or directory (2) 打开跟踪文件时出错:没有这样的文件或目录(2),解决方案? - error opening trace file: No such file or directory (2), Solution? 打开跟踪文件时出错。 没有这样的文件或目录[2] - Error opening trace file. No such file or directory [2] HttpURLConnection打开跟踪文件时出错:没有这样的文件或目录 - HttpURLConnection Error opening trace file: no such file or directory E / Trace:错误打开跟踪文件:没有这样的文件或目录(2) - E/Trace﹕ error opening trace file: No such file or directory (2) 错误打开跟踪文件android权限被拒绝 - Error opening trace file android permission denied LogCat错误打开跟踪文件时出错:没有这样的文件或目录 - LogCat error Error opening trace file: no such file or directory 是什么原因导致打开跟踪文件错误:没有这样的文件或目录? - What cause the error opening trace file: No such file or directory?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM