Solved Issue Reading Main Class

Discussion in 'Plugin Development' started by AgroCupcake, Jul 9, 2016.

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

    AgroCupcake

    I am making a plugin for my server. Currently, I am having an with the server not being able to find certain files in my plugin. I am getting an error saying my main class is missing, but when I extracted it, It was there.
    Code:
    [17:47:48] [Server thread/ERROR]: Could not load 'plugins\LlamaEnvoys.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: Cannot find main class `com.agrocupcake.llamaenvoys.mainclass'
        at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:66) ~[ServerJarS.jar:git-Spigot-5391d73-0ebb9c7]
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:131) ~[ServerJarS.jar:git-Spigot-5391d73-0ebb9c7]
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:329) ~[ServerJarS.jar:git-Spigot-5391d73-0ebb9c7]
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) [ServerJarS.jar:git-Spigot-5391d73-0ebb9c7]
        at org.bukkit.craftbukkit.v1_10_R1.CraftServer.loadPlugins(CraftServer.java:297) [ServerJarS.jar:git-Spigot-5391d73-0ebb9c7]
        at net.minecraft.server.v1_10_R1.DedicatedServer.init(DedicatedServer.java:202) [ServerJarS.jar:git-Spigot-5391d73-0ebb9c7]
        at net.minecraft.server.v1_10_R1.MinecraftServer.run(MinecraftServer.java:539) [ServerJarS.jar:git-Spigot-5391d73-0ebb9c7]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_91]
    Caused by: java.lang.ClassNotFoundException: com.agrocupcake.llamaenvoys.mainclass
        at java.net.URLClassLoader.findClass(Unknown Source) ~[?:1.8.0_91]
        at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:101) ~[ServerJarS.jar:git-Spigot-5391d73-0ebb9c7]
        at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:86) ~[ServerJarS.jar:git-Spigot-5391d73-0ebb9c7]
        at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_91]
        at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_91]
        at java.lang.Class.forName0(Native Method) ~[?:1.8.0_91]
        at java.lang.Class.forName(Unknown Source) ~[?:1.8.0_91]
        at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:64) ~[ServerJarS.jar:git-Spigot-5391d73-0ebb9c7]
        ... 7 more
    [17:47:49]
    As I said my main Class exists.
    My plugin.yml is:
    Code:
    name: LlamaEnvoys
    version: 1.0
    main: com.agrocupcake.llamaenvoys.mainclass
    Author: AgroCupcake
    
    commands:
      Envoy:
        description: Use This to View Envoy Timer
        usage: /envoy
      AddEnvoy:
        description: Adds an Envoy drop location where you are standing
        usage: /addenvoy
    Any Help
    -- AgroCupcake
     
  2. Offline

    SuperSniper

    is "mainclass" the name of the class that extends JavaPlugin?
     
  3. Offline

    AgroCupcake

    Yes It is, mainclass.java
     
  4. Offline

    ipodtouch0218

    If the line says
    Code:
    public class mainclass {
    }
    Make it say
    Code:
    public class mainclass extends JavaPlugin {
    }
    The main class has to extend JavaPlugin for bukkit to recognize the class.
     
  5. Offline

    AgroCupcake

    It aready does
     
  6. Offline

    ipodtouch0218

    Can you post the code of your main class?
     
  7. Offline

    AgroCupcake

    Sure:
    Code:
    package com.agrocupcake.llamaenvoys;
    import org.bukkit.command.CommandExecutor
    import org.bukkit.command.PluginCommand
    import org.bukkit.configuration.file.FileConfiguration
    import org.bukkit.configuration.file.FileConfigurationOptions
    import org.bukkit.plugin.PluginDescriptionFile
    import org.bukkit.plugin.java.JavaPlugin
    
    
    
    import com.agrocupcake.llamaenvoys.commands.EnvoyAddCoords;
    import com.agrocupcake.llamaenvoys.commands.EnvoyMain;
    import java.util.logging.Logger;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.PluginCommand;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.FileConfigurationOptions;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class mainclass extends JavaPlugin {
        public void onEnable() {
            PluginDescriptionFile descFile = this.getDescription();
            Logger logger = this.getLogger();
            logger.info(String.valueOf(descFile.getName()) + "Has Been Enabled (v: " + descFile.getVersion() + " )");
            this.getCommand("envoy").setExecutor((CommandExecutor)new EnvoyCommand(this));
            this.getCommand("addenvoy").setExecutor((CommandExecutor)new EnvoyAddCoords(this));
            this.registerConfig();
        }
    
        private void registerConfig() {
            this.getConfig().options().copyDefaults(true);
            this.saveConfig();
        }
    
        public void onDisable() {
            PluginDescriptionFile descFile = this.getDescription();
            Logger logger = this.getLogger();
            logger.info(String.valueOf(descFile.getName()) + "Has Been Disabled (v: " + descFile.getVersion() + " )");
        }
    }
    
    
    Hmm, now I am getting an error saying the package fragment root does not exist for mainclass.java when I am trying to export.


    EDIT:
    Fixed That, Now I can test, I will get back to you later

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

    ipodtouch0218

    You don't have "@Override" above onEnable() and onDisable()... that may be the problem with it.
     
  9. Offline

    AgroCupcake

    Nope, same error occured.
     
  10. Offline

    Caedus

    Try adding a line of space between the package and first imports.

    Also, this isn't the reason for your error but the whole logger stuff in onEnable() and onDisable() is entirely unnecessary, bukkit does it automatically for you.
     
  11. Offline

    mine-care

    Please don't watch TheBcBroz to learn Bukkit... For instance here, there is no need for all that as bukkit allready shows the enable and disable messages in that format.


    The only problem this could theoretically cause would be a method not being run from the subclass, but certainly not a ClassNotFoundException.

    I dont see how that would help. The problem isnt that the code is not compiling, it is an exception thrown during runtime. a ClassNotFoundException pointing to the main class. A syntax change wouldnt do much. Also the line space between package and imports only changes the way you see it, not the way the compiler 'sees' the code. You could technically put everything on the same line and the compiler would be able to turn it into an actual program that runs.



    @AgroCupcake
    Please export the jar file to a directory as you do normally and then open the jar file with a Zip file opener such as WinRar or 7zip. Search for the class 'mainclass' in /com/agrocupcake/llamaenvoys/. Is it there?
    Also please follow naming conventions.
     
    AgroCupcake and bwfcwalshy like this.
  12. Offline

    AgroCupcake

    I have done that many times, as it is the most logical answer; Yes It Is

    Should I delete the onDisable code then?
     
    Last edited: Jul 10, 2016
  13. Offline

    Caedus

    Yes, currently you do not need it.
     
  14. Offline

    AgroCupcake

    So, Now I am working on coding a part that places a chest at certain coordinates defined in the config.
    I currently have this code:
    Code:
            @EventHandler
           List<String> Envoys this.getConfig().getStringList("Envoys")
            for (String l : Envoys){
           public void onBlockPlace(BlockPlaceEvent event) {
                final Block block = event.getBlock();
                if(block.getType() == Material.CHEST){
                    Chest chest = (Chest) event.getBlock().getState();
                    Inventory chestinv = chest.getBlockInventory()
    I am stuck trying to have the chest spawn at the locations defined.
    Any Help?

    EDIT: Just noticed when troubleshooting that my src folder is empty, is this an issue for bukkit by any chance?
    EDIT#2: No more errors in console, it was that they were not in the src, Thanks!
     
    Last edited: Jul 11, 2016
Thread Status:
Not open for further replies.

Share This Page