私は現在LibGDXゲームを書いていますが、スプライトシートの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
なぜファイルを識別できるのに、ファイルを開くことができないというIOExceptionが発生するのですか?助けてくれてありがとう。必要に応じてさらに情報を提供します。