简体   繁体   English

Libgdx FileHandle list()方法在jar文件中不起作用

[英]Libgdx FileHandle list() method doesn't work in jar file

I created a desktop game in eclipse using Libgdx. 我使用Libgdx在Eclipse中创建了一个桌面游戏。 The game runs great in eclipse, however the FileHandle list() method doesn't work when exported to a jar file. 游戏在eclipse中运行良好,但是FileHandle list()方法在导出到jar文件时不起作用。 I used the following lines of code: 我使用了以下几行代码:

songFiles = Gdx.files.internal("./bin/" + "songs/").list();
System.out.println(songFiles[0]);

Again, in eclipse it prints the file location.However when exported to a jar, I get a java.lang.ArrayIndexOutOfBoundsException: 0 error. 同样,在eclipse中它会打印文件位置。但是,当导出到jar中时,会出现java.lang.ArrayIndexOutOfBoundsException: 0错误。

Cannot export default Java libGDX project as a jar from Eclipse looks similar to the issue that I am having 无法将默认的Java libGDX项目导出为Eclipse中的jar,看起来类似于我遇到的问题

It says you created the list or array but u didn't initialize it with length. 它说您创建了列表或数组,但您未使用长度对其进行初始化。 That's why you have 0 at the end of error message. 这就是为什么错误消息末尾有0。

由于list()方法不能在桌面应用程序上使用,因此我将通过将歌曲目录中的文件名读写到文本文件来解决此问题。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM