Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android内容资源NotFoundException:_Java_Android_Xml_Android Assets - Fatal编程技术网

Java Android内容资源NotFoundException:

Java Android内容资源NotFoundException:,java,android,xml,android-assets,Java,Android,Xml,Android Assets,我开发了一个Java Android应用程序,但我遇到了一个问题:) 我想加载一个XML文件 AssetManager assetManager = getAssets(); InputStream questionsFile = assetManager.open("questions.xml"); document = builder.parse(questionsFile); NodeList nList = document.getElementsByTagName("question"

我开发了一个Java Android应用程序,但我遇到了一个问题:)

我想加载一个XML文件

AssetManager assetManager = getAssets();
InputStream questionsFile = assetManager.open("questions.xml");
document = builder.parse(questionsFile);
NodeList nList = document.getElementsByTagName("question");
XML位于Asset文件夹中,但我得到一个res Resources NotFoundException

谢谢你的帮助

这是我的XML文件:

<questions>
    <question text='Qui est le réalisateur de blade runner ?'>
        <answer trueAnswer='false'>Stanley Kubrick</answer>
        <answer trueAnswer='false'>Steven Spielberg</answer>
        <answer trueAnswer='true'>Ridley Scott</answer>
        <answer trueAnswer='false'>Roland emmerich</answer>
    </question>
    <question text='Ou se situe le siège social de la société Facebook ?'>
        <answer trueAnswer='true'>Palo Alto</answer>
        <answer trueAnswer='false'>Philadelphie</answer>
        <answer trueAnswer='false'>Dallas</answer>
        <answer trueAnswer='false'>Boston</answer>
    </question>
    <question text='Combien de saison a durée la série X files ?'>
        <answer trueAnswer='false'>1</answer>
        <answer trueAnswer='false'>5</answer>
        <answer trueAnswer='true'>7</answer>
        <answer trueAnswer='false'>9</answer>
    </question> 
</questions>
只能在Java中工作,不能在android中工作

谢谢大家的回答

///////////////////////////////////////////////////////

其工作原理如下:

NodeList nList = document.getElementsByTagName("question");
Toast.makeText(getBaseContext(),nList.getLength(), 
                    Toast.LENGTH_LONG).show();
AssetManager assetManager = getAssets();
document =    builder.parse(assetManager.open("XML/questions.xml"));
NodeList nList = document.getElementsByTagName("question");

textViewQuestion = (TextView) findViewById(R.id.textViewQuestion);
                  textViewQuestion.setText(nList.item(0).getAttributes().getNamedItem("text").getNodeValue());

清理并构建应用程序,然后再次启动你的应用程序

我也面临这个问题,在asset中创建子目录,并将此文件放入子目录和givepath assetManager.open(“subDir/questions.xml”)


它将工作..检查..

我已清理并重建了应用程序,但我得到了E/AndroidRuntime(1962):原因:android.content.res.Resources$NotFoundException:String resource ID#0x3错误againca请发布你的questions.xml代码?我已经测试了你的代码,它正在工作。我认为你的questions.xml文件出了问题。你能发布questions.xml文件的内容吗?你会发布你的LogCat或堆栈跟踪吗?