简体   繁体   English

“找不到适合的加载方法”怎么了?

[英]What's wrong with “no suitable method found for load”?

Sound doesn't play when running my app in android, so suggested workarounds include AssetManager to preload files: I want to preload all files when class is initialized and play it later in a sub-function. 在android中运行我的应用程序时声音无法播放,因此建议的解决方法包括AssetManager来预加载文件:我想在类初始化时预加载所有文件,稍后再在子函数中播放。

The manager should be globally used in the class, but it seems the definition is not the problem (tried local implementation, same error). 该管理器应在该类中全局使用,但似乎定义不是问题(尝试本地实现,相同错误)。

Here is the code: 这是代码:

public AssetManager manager=new AssetManager();

public InterpreterAudioPlugin() {
    //Preload all sounds
    FileHandle sounds=Gdx.files.internal("Sound");
    for (FileHandle file: sounds.list()){
        manager.load(Gdx.files.internal(file.toString()),Music.class);
        manager.finishLoading();
    }

It pops an error at load saying "no suitable method found for load". 它在加载时弹出错误,提示“找不到适合的加载方法”。 Not sure what "no suitable method" means here, since googling it revealed it is very specific to the function after, in my case "load". 不确定“没有合适的方法”在这里是什么意思,因为对其进行谷歌搜索后发现它是非常特定于该函数的,在我的情况下是“加载”。 Any help? 有什么帮助吗?

It doesn't exist a method load() which takes the Arguments: FileHandle and Class. 它不存在带有参数的方法load() :FileHandle和Class。 Possible load methods are: 可能的加载方法是:

load(AssetDescriptor)
load(String, Class)
load(String, Class, AssetLoaderParameters)

Your first argument must be a String and not a FileHandle. 您的第一个参数必须是字符串,而不是FileHandle。

Try this: 尝试这个:

FileHandle sounds=Gdx.files.internal("Sound");
for (FileHandle file: sounds.list()){
    manager.load("Sound/" + file.name(), Music.class);
}
manager.finishLoading();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM