我在AssetManager上寻找libgdx类,当我尝试使用load()方法加载文件时,桌面项目有效,但android项目无效。

这是错误:

12-26 23:15:23.243: E/AndroidRuntime(15488): FATAL EXCEPTION: GLThread 1008
12-26 23:15:23.243: E/AndroidRuntime(15488): com.badlogic.gdx.utils.GdxRuntimeException: com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load dependencies of asset: data/0.png

12-26 23:15:23.243: E/AndroidRuntime(15488): at com.badlogic.gdx.assets.AssetManager.handleTaskError(AssetManager.java:517)
12-26 23:15:23.243: E/AndroidRuntime(15488):    at com.badlogic.gdx.assets.AssetManager.update(AssetManager.java:351)
12-26 23:15:23.243: E/AndroidRuntime(15488):    at fr.orandjadev.utils.RessourcesManager.update(RessourcesManager.java:30)
12-26 23:15:23.243: E/AndroidRuntime(15488):    at fr.orandjadev.samourai.Game.render(Game.java:36)
12-26 23:15:23.243: E/AndroidRuntime(15488):    at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:499)
12-26 23:15:23.243: E/AndroidRuntime(15488):    at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1462)
12-26 23:15:23.243: E/AndroidRuntime(15488):    at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1216)
12-26 23:15:23.243: E/AndroidRuntime(15488): Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load dependencies of asset: data/0.png

12-26 23:15:23.243: E/AndroidRuntime(15488):    at com.badlogic.gdx.assets.AssetLoadingTask.handleAsyncLoader(AssetLoadingTask.java:119)
12-26 23:15:23.243: E/AndroidRuntime(15488):    at com.badlogic.gdx.assets.AssetLoadingTask.update(AssetLoadingTask.java:89)
12-26 23:15:23.243: E/AndroidRuntime(15488):    at com.badlogic.gdx.assets.AssetManager.updateTask(AssetManager.java:454)
12-26 23:15:23.243: E/AndroidRuntime(15488):    at com.badlogic.gdx.assets.AssetManager.update(AssetManager.java:349)
12-26 23:15:23.243: E/AndroidRuntime(15488):    ... 5 more
12-26 23:15:23.243: E/AndroidRuntime(15488): Caused by: com.badlogic.gdx.utils.GdxRuntimeException: com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: data/0.png

12-26 23:15:23.243: E/AndroidRuntime(15488):    at com.badlogic.gdx.utils.async.AsyncResult.get(AsyncResult.java:46)
12-26 23:15:23.243: E/AndroidRuntime(15488):    at com.badlogic.gdx.assets.AssetLoadingTask.handleAsyncLoader(AssetLoadingTask.java:117)
12-26 23:15:23.243: E/AndroidRuntime(15488):    ... 8 more
12-26 23:15:23.243: E/AndroidRuntime(15488): Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: data/0.png

12-26 23:15:23.243: E/AndroidRuntime(15488):    at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:140)
12-26 23:15:23.243: E/AndroidRuntime(15488):    at com.badlogic.gdx.assets.loaders.TextureLoader.loadAsync(TextureLoader.java:72)
12-26 23:15:23.243: E/AndroidRuntime(15488):    at com.badlogic.gdx.assets.loaders.TextureLoader.loadAsync(TextureLoader.java:41)
12-26 23:15:23.243: E/AndroidRuntime(15488):    at com.badlogic.gdx.assets.AssetLoadingTask.call(AssetLoadingTask.java:69)
12-26 23:15:23.243: E/AndroidRuntime(15488):    at com.badlogic.gdx.assets.AssetLoadingTask.call(AssetLoadingTask.java:34)
12-26 23:15:23.243: E/AndroidRuntime(15488):    at com.badlogic.gdx.utils.async.AsyncExecutor$2.call(AsyncExecutor.java:65)
12-26 23:15:23.243: E/AndroidRuntime(15488):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
12-26 23:15:23.243: E/AndroidRuntime(15488):    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
12-26 23:15:23.243: E/AndroidRuntime(15488):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
12-26 23:15:23.243: E/AndroidRuntime(15488):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
12-26 23:15:23.243: E/AndroidRuntime(15488):    at java.lang.Thread.run(Thread.java:856)
12-26 23:15:23.243: E/AndroidRuntime(15488): Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Error reading file: data/0.png
 (Internal)
12-26 23:15:23.243: E/AndroidRuntime(15488):    at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:74)
12-26 23:15:23.243: E/AndroidRuntime(15488):    at com.badlogic.gdx.files.FileHandle.readBytes(FileHandle.java:217)
12-26 23:15:23.243: E/AndroidRuntime(15488):    at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:137)
12-26 23:15:23.243: E/AndroidRuntime(15488):    ... 10 more
12-26 23:15:23.243: E/AndroidRuntime(15488): Caused by: java.io.FileNotFoundException: data/0.png

12-26 23:15:23.243: E/AndroidRuntime(15488):    at android.content.res.AssetManager.openAsset(Native Method)
12-26 23:15:23.243: E/AndroidRuntime(15488):    at android.content.res.AssetManager.open(AssetManager.java:406)
12-26 23:15:23.243: E/AndroidRuntime(15488):    at android.content.res.AssetManager.open(AssetManager.java:380)
12-26 23:15:23.243: E/AndroidRuntime(15488):    at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:72)
12-26 23:15:23.243: E/AndroidRuntime(15488):    ... 12 more


我设置了这样的资源。

public void loadTexture(String path){
    assetmanager.load(path, Texture.class);
}


路径就像data/0.png

以前在我的代码中,我使用Gdx.files.internal(somepaths);,它可以完美运行...
我想我听不懂。桌面项目链接到android项目的资产文件夹。

最佳答案

将文件保存在资产文件夹中时,必须始终使用Gdx.files.internal(path)

它在台式机上而不是在android上运行的原因是文件系统在所有平台上的实现方式都不同。因此,最好的选择是使用libgdx本身提供的平台无关的api,而不是直接给出路径。

引擎盖下有文件路径解析器,可以处理平台特有的问题。
有关更多信息,请参考https://code.google.com/p/libgdx/wiki/FileHandling

希望这可以帮助。

关于java - libgdx:AssetsManager错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20792872/

10-14 21:47