libgdx - Gdx.files.internal(); - >文件未找到

时间:2014-07-03 15:04:40

标签: java eclipse audio libgdx desktop

我在使用libgdx的Gdx.files.internal()时遇到了麻烦。 似乎每次我作为桌面应用程序运行它时都会遇到这个主要错误:

  

引起:com.badlogic.gdx.utils.GdxRuntimeException:找不到文件:   \ data \ sounds \ music \ mainmusic.mp3(内部)at   com.badlogic.gdx.files.FileHandle.read(FileHandle.java:136)at   com.badlogic.gdx.backends.lwjgl.audio.Mp3 $音乐。(Mp3.java:42)     ......还有10个

我已经阅读了5个不同的主题,其中一个似乎是最可能的问题所以我试过......

  1. 在资产
  2. 下创建数据文件夹
  3. 刷新日食探险家
  4. 项目>
  5. 在bin(核心)中手动创建资产/数据文件夹
  6. 三重检查文件路径
  7. 重新启动IDE
  8. 我的完整路径是 / Flipcrew Legends-桌面/资产/数据/声音/音乐/ mainmusic.mp3

    公共类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);
    
    }
    

    这个......似乎......似乎有效..

    @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);
    }
    

    路径:/ Flipcrew Legends-desktop / assets / data / images / main / splash.png

    //其余的类被省略b / c它似乎没有必要(我可以根据要求添加它)

    //不幸的是,Gdx.audio.newMusic似乎没有直接的字符串路径方法所以我无法尝试

    其他信息: - >我已经尝试从桌面文件夹中复制资源文件夹从核心到无效(删除后) - >一个线程说libgdx通常从android文件夹中获取数据,然后将其应用到桌面上(不幸的是我只用桌面开始,没有android)但是我猜测libgdx自那个帖子的最后日期以来每晚更新一次,可能还有其他选择吗?

    编辑:

    1. 刚刚将资产/数据/等等恢复为资产/等等..... 即使new Texture(path);得到相同的错误 - 仍然无法正常工作...上面重试的方法,将在发布后重新启动计算机,可能是一个编译问题。

    2. 重新启动计算机,没有区别

4 个答案:

答案 0 :(得分:5)

转到Project->尝试“清理”您的项目清洁。也可以通过右键单击并使用Gradle->尝试“刷新”您的libGDX桌面文件夹。全部刷新

libGDX使用链接文件夹。您只需将文件复制到您的资产文件夹之一(在eclipse中执行此操作,而不是在文件资源管理器中执行此操作。)

答案 1 :(得分:2)

对我有用的是,我必须进入资产 - >构建路径 - >配置包含/排除。我必须将所有需要的文件夹和文件添加到“包含”部分。

答案 2 :(得分:1)

答案是LibGDX之外的,因为有人已经回答了原始问题。答案可能有助于LibGDX外部文件的相关工作。

假设

存在包装……苹果,橙子,葡萄。尝试使用相对路径。

  1. Apple包含文件Temp1.txt。
  2. 橙色包含文件Temp2.​​txt。
  3. 葡萄包含文件Temp3.txt。

以以下格式访问文件...

  • ” / Apple / Temp1.txt”
  • “ / Orange / Temp2.​​txt”
  • ” / Grape / Temp3.txt”

答案 3 :(得分:0)

我在Android Studio上遇到了同样的问题。我为每种资产都应用了直接路径。

“ C:\ Users \ Admin \ Desktop \ test1 \ android \ assets / starfish.png”

enter public void create()
    {
        batch = new SpriteBatch();
        turtleTexture = new Texture( Gdx.files.internal("C:\\Users\\Admin\\Desktop\\test1\\android\\assets/starfish.png") );
        turtleX = 20;
        turtleY = 20;
        turtleRectangle = new Rectangle( turtleX, turtleY,
                turtleTexture.getWidth(), turtleTexture.getHeight() );
        starfishTexture = new Texture( Gdx.files.internal("C:\\Users\\Admin\\Desktop\\test1\\android\\assets/starfish.png") );
        starfishX = 380;
        starfishY = 380;
        starfishRectangle = new Rectangle( starfishX, starfishY,
                starfishTexture.getWidth(), starfishTexture.getHeight() );
        oceanTexture = new Texture( Gdx.files.internal("C:\\Users\\Admin\\Desktop\\test1\\android\\assets/water.jpg") );
        winMessageTexture = new Texture( Gdx.files.internal("C:\\Users\\Admin\\Desktop\\test1\\android\\assets/you-win.png") );
        win = false;
    }