vendredi 4 août 2017

Java Reflections API throwing NoSuchMethodError when getting all classes in package

I'm trying to get all the classes in the main package of my Bukkit plugin using this API

This is my code to get all of the classes

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;
}

}

I was previously using a different way of getting all the classes, which was a bit more clunky, and didn't use this api. However, upon making subclasses, this method broke. I've tried a few different variations of this code, but it still throws a NoSuchMethodError.

Here's the Stack Trace

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]

Any help would be greatly appreciated :)





Aucun commentaire:

Enregistrer un commentaire