Java libgdx -- Gdx.files.internal(); --> 文件未找到
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24557268/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
libgdx -- Gdx.files.internal(); --> File Not Found
提问by
I've been having trouble using the Gdx.files.internal() from libgdx; it seems that every time I run it as a desktop application i get this main error:
我在使用 libgdx 中的 Gdx.files.internal() 时遇到了问题;似乎每次我将它作为桌面应用程序运行时,我都会遇到这个主要错误:
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: File not found: \data\sounds\music\mainmusic.mp3 (Internal) at com.badlogic.gdx.files.FileHandle.read(FileHandle.java:136) at com.badlogic.gdx.backends.lwjgl.audio.Mp3$Music.(Mp3.java:42) ... 10 more
引起:com.badlogic.gdx.utils.GdxRuntimeException:找不到文件:\data\sounds\music\mainmusic.mp3(内部)在 com.badlogic.gdx.files.FileHandle.read(FileHandle.java:136) at com.badlogic.gdx.backends.lwjgl.audio.Mp3$Music.(Mp3.java:42) ... 10 更多
I've read 5 separate threads in the matter, one of which seemed like was the most likely problem so I've tried...
我已经阅读了 5 个单独的线程,其中一个似乎是最有可能的问题,所以我尝试过......
- creating a data folder under assets
- refreshing the eclipse explorer
- Project > clean
- manually creating an assets/data folder in bin (in core)
- triple checking file paths
- restarting the IDE
- 在资产下创建数据文件夹
- 刷新日食资源管理器
- 项目 > 清洁
- 在 bin 中手动创建资产/数据文件夹(在核心中)
- 三重检查文件路径
- 重新启动IDE
my complete path is in /Flipcrew Legends-desktop/assets/data/sounds/music/mainmusic.mp3
我的完整路径在 /Flipcrew Legends-desktop/assets/data/sounds/music/mainmusic.mp3
public class SplashScreen implements Screen{
公共类 SplashScreen 实现了 Screen{
final FlipcrewLegends game;
Texture splashTexture;
Sprite splashSprite;
SpriteBatch batch;
TweenManager manager;
Music introMusic;
public SplashScreen(FlipcrewLegends game) {
this.game = game;
introMusic = Gdx.audio.newMusic(Gdx.files.internal("data/sounds/music/mainmusic.mp3"));
introMusic.setLooping(true);
}
This However... seems to be working..
这不过......似乎正在工作..
@Override
public void show() {
splashTexture = new Texture("data/images/main/splash.png");
splashTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
splashSprite = new Sprite(splashTexture);
splashSprite.setColor(1, 1, 1, 0);
}
path: /Flipcrew Legends-desktop/assets/data/images/main/splash.png
路径:/Flipcrew Legends-desktop/assets/data/images/main/splash.png
// Rest of class is omitted b/c it doesn't seem necessary (I can add it if requested)
// 其余的课程被省略 b/c 似乎没有必要(如果需要,我可以添加它)
//unfortunately, Gdx.audio.newMusic doesnt seem to have a direct string path method so I couldn't try that out
//不幸的是,Gdx.audio.newMusic 似乎没有直接的字符串路径方法,所以我无法尝试
Additional Info: -> I've tried copying the assets folder in the desktop folder from core to no avail (deleted after) -> One thread said that libgdx usually takes the data from the android folder and then applies it to the desktop (unfortunately I started with only the desktop, no android) but I'm guessing libgdx has been nightly updated since the last date of that post, maybe an alternative has been added for that?
附加信息:-> 我尝试将桌面文件夹中的资产文件夹从核心复制但无济于事(之后删除)-> 一个线程说 libgdx 通常从 android 文件夹中获取数据,然后将其应用到桌面(不幸的是我只从桌面开始,没有安卓)但我猜自那篇文章的最后日期以来,libgdx 已经每晚更新,也许已经为此添加了替代方法?
edit:
编辑:
Just now after reverting assets/data/etc.... into assets/etc..... even the
new Texture(path);
is getting the same error - still doesn't work... retried methods above, will restart the computer after posting, might be a compiling issue.restarted computer, no difference
刚刚在恢复资产/数据/等.... 到资产/等..... 即使
new Texture(path);
是得到同样的错误 - 仍然不起作用...重试上述方法,发布后将重新启动计算机,可能是编译问题。重启电脑,没区别
采纳答案by Porlune
Try "cleaning" your project by going to Project-> Clean. Also try "refreshing" your libGDX desktop folder by right clicking and using Gradle-> Refresh All
尝试通过转到“项目”->“清理”来“清理”您的项目。还可以尝试通过右键单击并使用 Gradle-> Refresh All 来“刷新”您的 libGDX 桌面文件夹
libGDX uses linked folders. You only need to copy the file to one of your asset folders (do this in eclipse, not in file explorer.)
libGDX 使用链接文件夹。您只需要将文件复制到您的资产文件夹之一(在 eclipse 中执行此操作,而不是在文件资源管理器中。)
回答by user1904965
What worked for me is, I had to go into assets->Build Path -> Configure Inclusion/Exclusion. I had to add all of my needed folders and files into the Inclusion section.
对我有用的是,我必须进入资产-> 构建路径-> 配置包含/排除。我必须将所有需要的文件夹和文件添加到“包含”部分。
回答by David Cohn
Answer is for outside of LibGDX, since someone already answered the original question. The answer may help with related efforts with files outside of LibGDX.
答案是针对 LibGDX 之外的,因为有人已经回答了原始问题。答案可能有助于与 LibGDX 之外的文件相关的工作。
Assumption:
假设:
Packages exist ... Apple, Orange, Grape. Trying to use relative paths.
包存在......苹果,橙,葡萄。尝试使用相对路径。
- Apple contains the file, Temp1.txt.
- Orange contains the file, Temp2.txt.
- Grape contains the file, Temp3.txt.
- Apple 包含文件 Temp1.txt。
- Orange 包含文件 Temp2.txt。
- Grape 包含文件 Temp3.txt。
Access the files in the format, ...
以格式访问文件,...
- "/Apple/Temp1.txt"
- "/Orange/Temp2.txt"
- "/Grape/Temp3.txt"
- “/Apple/Temp1.txt”
- “/橙色/Temp2.txt”
- “/葡萄/Temp3.txt”