Solved No Such Method Exception (not as easy as you think)

Discussion in 'Plugin Development' started by Staartvin, Jan 24, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Staartvin

    Ok, for some reason, when I export my plugin in Eclipse and then run my local test server, I get this:

    Code:
    18:54:01 [SEVERE] Could not load 'plugins\SimpleSuffix.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.NoSuchMethodError: me.Staart
    vin.Commands.Commands.<init>(Lme/Staartvin/SimpleSuffix/SimpleSuffix;)V
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.j
    ava:182)
            at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.
    java:305)
            at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager
    .java:230)
            at org.bukkit.craftbukkit.v1_4_R1.CraftServer.loadPlugins(CraftServer.ja
    va:239)
            at org.bukkit.craftbukkit.v1_4_R1.CraftServer.reload(CraftServer.java:59
    4)
            at org.bukkit.Bukkit.reload(Bukkit.java:184)
            at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:
    23)
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:18
    6)
            at org.bukkit.craftbukkit.v1_4_R1.CraftServer.dispatchCommand(CraftServe
    r.java:514)
            at org.bukkit.craftbukkit.v1_4_R1.CraftServer.dispatchServerCommand(Craf
    tServer.java:506)
            at net.minecraft.server.v1_4_R1.DedicatedServer.al(DedicatedServer.java:
    260)
            at net.minecraft.server.v1_4_R1.DedicatedServer.r(DedicatedServer.java:2
    25)
            at net.minecraft.server.v1_4_R1.MinecraftServer.q(MinecraftServer.java:4
    94)
            at net.minecraft.server.v1_4_R1.MinecraftServer.run(MinecraftServer.java
    :427)
            at net.minecraft.server.v1_4_R1.ThreadServerApplication.run(SourceFile:8
    49)
    Caused by: java.lang.NoSuchMethodError: me.Staartvin.Commands.Commands.<init>(Lm
    e/Staartvin/SimpleSuffix/SimpleSuffix;)V
            at me.Staartvin.SimpleSuffix.SimpleSuffix.<init>(SimpleSuffix.java:27)
            at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
     
            at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
     
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Sou
    rce)
            at java.lang.reflect.Constructor.newInstance(Unknown Source)
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.j
    ava:178)
            ... 14 more
    I understand that Java can not find a certain class? The '<init>' shows me that it's something to do with a constructor of a certain class. I tried removing the 'Commands' class and copy all a new class with exact the same name, but it still gave me this error.

    I think there is a easy solution for this, but for some reason I can't seem to fix it myself.
    Sorry for bugging you, but yeah... It's driving me insane :p


    Main Class: http://pastebin.com/sBYawzjP
    Commands Class: http://pastebin.com/7BTLafiH


    OS: Windows 8 pro
    Java version (cmd 'java -version'): java version "1.6.0_37" Java(TM) SE Runtime Environment (build 1.6.0_37-b06) Java HotSpot(TM) Client VM (build 20.12-b01, mixed mode, sharing)
    CraftBukkit version: 1.4.7-R0.2 (Build #02612)
     
  2. can you give the sources?
     
  3. Offline

    tommycake50

    whats at SimpleSuffix.java line 27
    and show us the Commands class.
     
  4. Offline

    Staartvin

  5. Offline

    tommycake50

    instead of passing the instance into the construuctor as arguments,
    in the main class make a public static JavaPlugin instance;
    variable and in onEnable set it to this.
     
  6. Offline

    Staartvin

    S

    On line 27, I'm just declaring the Commands class.
    'public Commands commands = new Commands(this);'
     
  7. sometimes, weird errors like this are caused by a bug inside the ide, try restarting your ide and rebuilding your project
     
  8. Offline

    Staartvin

    I've already done that. :(

    I don't think this is the solution because all my other classes work just fine.
    They have exactly the same setup.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  9. Offline

    tommycake50

    ik its still as easy because all you have to do is static import them to use them w/o typing MainClass.instance.
     
  10. Offline

    Staartvin

    tommycake50
    I've learnt that using a static variable to access the main class is not really the way to go, though? I don't really want to change it as my other classes get initialised the same as the Commands one but don't act this weird. Isn't there just a simple solution?
     
  11. Offline

    camyono

    Who taught you that?
    It is ok to use a static reference to your MainClass because you normally won't call it a second time.

    So other question: Did you changed the bukkit.jar? ( maybe to a newer? ) or do you have cached versions of your Commands class without this constructor? It seems like this. Maybe you should force a rebuild of all resources it should handle this problem.
     
  12. Offline

    Staartvin

    camyono
    I've deleted my .jar completely and exported it again as a fresh new jar. I downloaded the latest craftbukkit version. #2612. It's still giving me the same error.
     
  13. Offline

    tommycake50

    can you try my idea and post again?
    just want to see if it works(always worth a shot)...
     
  14. Offline

    Staartvin

    Ok, I'll try it.

    Nope, still the same error.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  15. Offline

    camyono

    If this wont work, post some more code... just to follow how u init everything
     
  16. Offline

    tommycake50

    ok.
    do what camyono said.
     
    camyono likes this.
  17. Offline

    Staartvin

    Ok, here you go: Simple Suffix.class: http://pastebin.com/sBYawzjP
     
  18. Offline

    camyono

    it needs to init in the onEnable block ...

    If the class is accessed it will try to init it. But at this time you have no instance of your plugin i think

    BTW: please use CamelCase and write package name in lower.case
    Use getter and setter for your fields and make them private or protected and only public if it needs to be like this!
     
  19. Offline

    Staartvin

    Why do the other classes work then?
     
  20. Offline

    fireblast709

    Static should be avoided if possible (and yes, here it is possible to avoid it)

    Staartvin post SimpleSuffix.java please :3
     
    camyono likes this.
  21. Offline

    tommycake50

    you have a point there fire.
     
  22. Offline

    Staartvin

    Thanks for the side note, but I need to get this fixed ;)
     
  23. Offline

    camyono

    Did you tried it the way i said to you?
     
  24. Offline

    Staartvin

    Do you mean the 'rebuild all resources'?
     
  25. Offline

    camyono

    No... to init all your classes in onEnable and not in the class head
     
  26. Offline

    fireblast709

    no he ment move all the initializations that use the 'this' as parameter in the onEnable()
     
  27. Offline

    Staartvin

  28. Offline

    camyono

    Delete the Commands.class from bin and try to rebuild your jar.

    If this not help i am out here.
     
  29. Offline

    fireblast709

    Its almost like... you did some weird stuff with external libraries or something. Check if the Commands.class is in the same jar as the main class
     
  30. Offline

    camyono

    I think there is a cached version somewhere which dont have this constructor which is called :/
     
Thread Status:
Not open for further replies.

Share This Page