我正在尝试使用this API
获取Bukkit插件主包中的所有类这是获取所有课程的代码
public class ClassFinder {
public static Set<Class<?>> getClasses(String packageName) {
Set<Class<?>> classes= new HashSet<>();
Reflections reflections = new Reflections(packageName);
classes=reflections.getSubTypesOf(Object.class);
return classes;
}
}
我以前使用不同的方式来获取所有类,这有点笨重,并且没有使用这个api。然而,在制作子类时,这种方法破裂了。我尝试过这段代码的一些不同变体,但它仍然会抛出NoSuchMethodError。
这是堆栈跟踪
java.lang.NoSuchMethodError: com.google.common.collect.Sets$SetView.iterator()Lcom/google/common/collect/UnmodifiableIterator;
at org.reflections.Reflections.expandSuperTypes(Reflections.java:380) ~[?:?]
at org.reflections.Reflections.<init>(Reflections.java:126) ~[?:?]
at org.reflections.Reflections.<init>(Reflections.java:168) ~[?:?]
at org.reflections.Reflections.<init>(Reflections.java:141) ~[?:?]
at pro.pvpgod.core.utils.ClassFinder.getClasses(ClassFinder.java:15) ~[?:?]
at pro.pvpgod.core.Core.registerCommands(Core.java:109) ~[?:?]
at pro.pvpgod.core.Core.onEnable(Core.java:95) ~[?:?]
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:271) ~[spigot-1.11.2.jar:git-Spigot-3fb9445-6e3cec8]
at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:337) [spigot-1.11.2.jar:git-Spigot-3fb9445-6e3cec8]
at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [spigot-1.11.2.jar:git-Spigot-3fb9445-6e3cec8]
at org.bukkit.craftbukkit.v1_11_R1.CraftServer.enablePlugin(CraftServer.java:376) [spigot-1.11.2.jar:git-Spigot-3fb9445-6e3cec8]
at org.bukkit.craftbukkit.v1_11_R1.CraftServer.enablePlugins(CraftServer.java:326) [spigot-1.11.2.jar:git-Spigot-3fb9445-6e3cec8]
at org.bukkit.craftbukkit.v1_11_R1.CraftServer.reload(CraftServer.java:750) [spigot-1.11.2.jar:git-Spigot-3fb9445-6e3cec8]
at org.bukkit.Bukkit.reload(Bukkit.java:540) [spigot-1.11.2.jar:git-Spigot-3fb9445-6e3cec8]
at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:25) [spigot-1.11.2.jar:git-Spigot-3fb9445-6e3cec8]
at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) [spigot-1.11.2.jar:git-Spigot-3fb9445-6e3cec8]
at org.bukkit.craftbukkit.v1_11_R1.CraftServer.dispatchCommand(CraftServer.java:650) [spigot-1.11.2.jar:git-Spigot-3fb9445-6e3cec8]
at org.bukkit.craftbukkit.v1_11_R1.CraftServer.dispatchServerCommand(CraftServer.java:636) [spigot-1.11.2.jar:git-Spigot-3fb9445-6e3cec8]
at net.minecraft.server.v1_11_R1.DedicatedServer.aM(DedicatedServer.java:437) [spigot-1.11.2.jar:git-Spigot-3fb9445-6e3cec8]
at net.minecraft.server.v1_11_R1.DedicatedServer.D(DedicatedServer.java:400) [spigot-1.11.2.jar:git-Spigot-3fb9445-6e3cec8]
at net.minecraft.server.v1_11_R1.MinecraftServer.C(MinecraftServer.java:678) [spigot-1.11.2.jar:git-Spigot-3fb9445-6e3cec8]
at net.minecraft.server.v1_11_R1.MinecraftServer.run(MinecraftServer.java:576) [spigot-1.11.2.jar:git-Spigot-3fb9445-6e3cec8]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_131]
非常感谢任何帮助:)