我目前正在编写一个 LibGDX 游戏,我需要为 spritesheet 打开一个 XML 文件。不幸的是,当我尝试打开文件时,我得到一个IOException
. 文件存在于正确的位置,项目已清理并保持最新等。
这是踢球者:LibGDX 将打开并显示同一目录中的图像文件,实际上会在它自己的FileHandle
对象中获取 XML 文件(我已经让它的大小和它匹配)。然而,当我将文件发送到 SAX 解析器时,我得到一个异常,导致我回到文件,说它无法打开它。
这是ClipSprite
类中的问题代码行:
private void parseConfigFile(FileHandle file) throws ParserConfigurationException, SAXException
{
//Use a SAX parser to get the data out of the XML file.
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
XMLConfigHandler handler = new XMLConfigHandler();
//Parse through the document
try
{
parser.parse(file.path(),handler); //IOException here
}
这是我在create
主 LibGDX 类的方法中选择游戏中文件的代码
//This loads a png file
texture = new Texture(Gdx.files.internal("data/graphics/CDE1/CDE1.png"));
texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
TextureRegion region = new TextureRegion(texture, 0, 0, 512, 275);
//Here I load the xml file and it tells me how many bytes it is
Gdx.app.error("File","xml bytes:"+Gdx.files.internal("data/graphics/CDE1/CDE1.xml").length());
//Here I load the same file and it crashes
//Note that it looks in the subdirectory and finds /CDE1.xml properly
animation = new ClipSprite("data/graphics/CDE1");
来自 logcat 的错误:
java.io.IOException: Couldn't open data/graphics/CDE1/CDE1.xml
为什么它可以识别文件,但我仍然收到关于无法打开它的 IOExceptions?感谢您的帮助,如有必要,我会提供更多信息。