如何将文件保存在资产中以便它可以在 Android Studio 中正确加载?

How to save file in assets so it can be properly loaded in Android Studio?

我正在按照有关创建 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,所以必须进行不同的方法调用吗?

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