我目前正在编写一个LibGDX游戏,需要打开一个精灵表的XML文件。不幸的是,当我尝试打开文件时,会出现
关键在于:LibGDX可以打开和显示同一目录中的图像文件,并且实际上会在自己的
以下是
为什么它可以识别文件,但我仍然收到无法打开它的IOException?感谢您的帮助,如果需要,我会提供更多信息。
IOException
。文件存在于正确的位置,项目已经清理并且是最新的等等。关键在于:LibGDX可以打开和显示同一目录中的图像文件,并且实际上会在自己的
FileHandle
对象中获取XML文件(我已经让它logcat大小并且匹配)。但是,当我将文件发送到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
}
以下是在主要的LibGDX类中的create
方法中选择游戏文件的代码:
//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");
日志记录错误信息:
java.io.IOException: Couldn't open data/graphics/CDE1/CDE1.xml
为什么它可以识别文件,但我仍然收到无法打开它的IOException?感谢您的帮助,如果需要,我会提供更多信息。
Gdx.files.internal(path)
来获取FileHandle
,然后使用.file()
来获取File
。 - GraphicsMuncher