【问题标题】:How to save file in assets so it can be properly loaded in Android Studio?如何将文件保存在资产中,以便可以在 Android Studio 中正确加载?
【发布时间】:2015-01-24 08:28:00
【问题描述】:

我正在按照有关创建 Flappy Bird 副本的指南进行操作。 - http://www.kilobolt.com/day-6-adding-graphics---welcome-to-the-necropolis.html

我遇到问题的步骤是从资产目录加载纹理。有作者关于如何执行此操作的说明。

以及他用于实际加载纹理的代码

        texture = new Texture(Gdx.files.internal("data/texture.png"));

我的文件结构是这样的(我用的是Android Studio 1.0,作者用的是eclipse)

我必须在资产文件夹中手动创建数据目录。但是,当我尝试运行应用程序时,我得到了这些异常

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: data/texture.png
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: File not found: data\texture.png (Internal)

有谁知道问题出在哪里? texture.png 显然位于资产的数据目录中。如作者所述,我还确保在将 .png 文件复制到数据目录后立即清理项目。(以便可以正确加载资源)。问题仅仅是因为使用了两个不同的 IDES,所以必须进行不同的方法调用吗?

【问题讨论】:

    标签: android libgdx filenotfoundexception runtimeexception file-not-found


    【解决方案1】:

    您正在尝试运行桌面应用程序。由于assets 位于android 项目中,您必须为桌面项目显式设置工作目录。转到Edit Configurations...,选择桌面配置并将Working directory 设置为android assets 文件夹的路径。就像是:

    【讨论】:

    • 谢谢 :) 作者在eclipse中没有这样做是有原因的吗?
    • 对不起,我对指南或 Eclipse 一无所知 :)
    猜你喜欢
    • 1970-01-01
    • 2014-06-03
    • 1970-01-01
    • 2017-12-05
    • 1970-01-01
    • 2014-12-29
    • 2016-05-29
    • 2019-09-17
    • 2019-06-21
    相关资源
    最近更新 更多