ClassNotFoundException Error always

Discussion in 'Plugin Development' started by killerrj8, May 31, 2011.

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

    killerrj8

    It doesnt matter which plugin i code / make. The whole time i get "ClassNotFoundException" Errors. WTF is that. It doesnt if it is a command driven plugin. A Login Message , Block placing , i always get ClassNotFound Exception . Does anyone know what this is

    anyone

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

    nisovin

    If you want help you'll post your code. Including your plugin.yml file.
     
  3. Offline

    killerrj8

    ok ok i thought it doesnt matter cause it happens always but ok here it is :
    Code:
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.util.logging.Logger;
    
    import org.bukkit.ChatColor;
    import org.bukkit.event.Event;
    import org.bukkit.event.Event.Priority;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Midas extends JavaPlugin{
        private final MidasPlayerListener pListener = new MidasPlayerListener(this);
        public String Item = null;
    
        private static Logger log = Logger.getLogger("Minecraft");
         public static String name = "Midas";
         public static String version = "1.0";
       
        @Override
        public void onDisable() {
            log.info("Midas Version " + version + " disabled.");
    
        }
    
        @Override
        public void onEnable() {
            if (!new File(getDataFolder().toString()).exists() ) {
                new File(getDataFolder().toString()).mkdir();
            }
    
            File MidasItem = new File(getDataFolder()+"/MidasItem.txt");
            if (!MidasItem.exists()) {
                new File(getDataFolder().toString()).mkdir();
                try {
                    MidasItem.createNewFile();
                }
                catch (IOException ex) {
                    System.out.println("Failed to create file: "+MidasItem.getPath());
                }
    
                try {
                    BufferedWriter out = new BufferedWriter(new FileWriter(MidasItem, true));
                    out.write("#Just write ID here .");
                    out.close();
                }
                catch (Exception e) {
                    System.out.println("Failed to write config file: "+e);
                }
            }
            try {
                BufferedReader read = new BufferedReader(new FileReader(MidasItem));
                Item = read.readLine();
                read.close();
            } catch (IOException e) {
                System.out.println("Failed create File: MidasItem: "+e);
                e.printStackTrace();
            }
     
            System.out.println("Midas Version " + version + " is enabled.");
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvent(Event.Type.BLOCK_DAMAGE, pListener, Priority.Normal, this);
    
        }
    }
    
    So and the Listener :
    Code:
    package me.Fredbuffer.Midas;
    
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerListener;
    
    public class MidasPlayerListener extends PlayerListener{
        private final Midas plugin;
        public MidasPlayerListener(Midas instance) {
            plugin = instance;
        }
        public void onPlayerInteract(PlayerInteractEvent event){
            Player player = event.getPlayer();
            if(event.getAction().equals(Action.LEFT_CLICK_BLOCK)){
                Block block = event.getClickedBlock();
                if(player.getItemInHand().getType() == Material.AIR) {
                    block.setType(Material.GOLD_BLOCK);
                    return;
                }
            }
        }
    
    }
    
    Now the Plugin.yml :


    Code:
    name: Midas
    main: me.Fredbuffer96.Midas.Midas
    version: 1.0
    author: Fredbuffer96
    description: >
      Changes Blocks to Gold. No Commands.
     
  4. Offline

    nisovin

    This:
    Code:
    main: me.Fredbuffer96.Midas.Midas
    Does not match your package names. Your main class doesn't seem to have a package at all (didn't copy it maybe?) and your listener class has this:
    Code:
    package me.Fredbuffer.Midas;
    See the difference?
     
  5. Offline

    DreadKyller

    @nisovin :If you look at his listener, he does not import his main class, meaning it's in the same package, which is me.Fredbuffer.Midas, so his main class would be me.Fredbuffer.Midas.Midas because the class Midad is in the package Midas as well, so it would be two

    Anyways @killerrj8 you should probably try it though, just incase
     
  6. Offline

    Jeyge

    That still doesn't change his plugins.yml from using the wrong package.
    Code:
    main: me.Fredbuffer96.Midas.Midas
    
    Which I think was the main point and if he used a package in his main class was somewhat optional. The key problem is the 96 in Fredbuffer96.
     
  7. Offline

    DreadKyller

    Oo, I didn't see that, and @Jeyge : whatever, the main class is not optional, it will find a package and say, which class in this fkin package am I supposed to use?
     
  8. Offline

    killerrj8

    oh i didnt marked that :/ here again with full copy of Main class:
    Code:
    package me.Fredbuffer.Midas;
    
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.util.logging.Logger;
    
    import org.bukkit.ChatColor;
    import org.bukkit.event.Event;
    import org.bukkit.event.Event.Priority;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Midas extends JavaPlugin{
        private final MidasPlayerListener pListener = new MidasPlayerListener(this);
        public String oof;
        public String kickmsg = null;
    
        private static Logger log = Logger.getLogger("Minecraft");
         public static String name = "Midas";
         public static String version = "1.0";
    
        @Override
        public void onDisable() {
            log.info("Midas Version " + version + " disabled.");
    
        }
    
        @Override
        public void onEnable() {
            if (!new File(getDataFolder().toString()).exists() ) {
                new File(getDataFolder().toString()).mkdir();
            }
    
            File MidasItem = new File(getDataFolder()+"/MidasItem.txt");
            if (!MidasItem.exists()) {
                new File(getDataFolder().toString()).mkdir();
                try {
                    MidasItem.createNewFile();
                }
                catch (IOException ex) {
                    System.out.println("Failed to create file: "+MidasItem.getPath());
                }
    
                try {
                    BufferedWriter out = new BufferedWriter(new FileWriter(MidasItem, true));
                    out.write("#Just write ID here .");
                    out.close();
                }
                catch (Exception e) {
                    System.out.println("Failed to write config file: "+e);
                }
            }
            try {
                BufferedReader read = new BufferedReader(new FileReader(MidasItem));
                kickmsg = read.readLine();
                read.close();
            } catch (IOException e) {
                System.out.println("Failed create File: MidasItem: "+e);
                e.printStackTrace();
            }
    
            System.out.println("Midas Version " + version + " is enabled.");
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvent(Event.Type.BLOCK_DAMAGE, pListener, Priority.Normal, this);
    
        }
    }
    

    EDIT: THanks guys i fixed it :) . Now it works good
     
  9. Offline

    ZephyrSigmar

    kickmsg in the bufferedreader? You copied the code from my onlyop :D [cake]
     
    killerrj8 likes this.
  10. Offline

    killerrj8

    yea i know dont want to release it ^^ just testing a bit

    BTW : as soon as i try my plugin with an on / off command it doenst work anymore :( Doesnt matter if i type on / off or the Basic command No Errors in Eclipse / or Bukkit console... It just doesnt work

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

    Jayjay110

    put your oncommand class here aswell, its probably because your checking if your plugin is enabled before you check if you can enable it...
     
  12. Offline

    DreadKyller

    how are you registering commands? are you just making the class or are you useing the

    getCommand("commandname").setExecutor(new YourCommandExecutor(this));?

    like JayJay said, you can have your onCommand boolean in your main, because JavaPlugin also implements CommandExecutor. However, this way every single command you type will go through the onCommand in your main, the getCommand() will only activate that class if that specific command is writen, so in an external class there is no need to check which command was done unless you set two executors to the same class, while in the main class you have to make sure the command is the right one.
     
  13. Offline

    killerrj8

    well i did it like ZephyrSigmar. I made a string and when args1 is "on" it writes the string as "on" and if you type "/Midas off" it should turn the string to "off" and in the listener i have the same , written before just with " if(plugin.String == "on") { "

    and then the rest. So basically this is my onCommand :
    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String parancs, String args[]) {
            if(sender.isOp()){
                if(parancs.equalsIgnoreCase("Midas")) {
                    if(args.length == 0) {
                        sender.sendMessage(ChatColor.BLUE + "Write '/Midas on' to turn it on.");
                        sender.sendMessage(ChatColor.BLUE + "Write '/Midas off' to turn Midas off.");
                        return true;
                    }
                    if(args.length == 1) {
                        String arg1 = args[0];
                        if(arg1.equals("on")){
                            oof = "on";
                            sender.sendMessage("Midas enabled! Everything you touch will be gold!");
                            return true;
                        }
    
                        if(arg1.equals("off")){
                            oof = "off";
                            sender.sendMessage("Midas disabled! You can touch anything without any effect.");
                            return true;
    
                        }
                        if(arg1.equals("state")) {
                            if(oof == "on"){
                                sender.sendMessage(ChatColor.BLUE + "Midas is Enabled.");
                                sender.sendMessage(ChatColor.BLUE + "Touch anything and it will turn to Gold.");
                                return true;
                            }
                            if(oof == "off" || oof==null){
                                sender.sendMessage(ChatColor.BLUE + "Midas is disabled.");
                                sender.sendMessage(ChatColor.BLUE + "You may touch anything without effect.");
                                return true;
                            }
                    }
                }
    
            }
                return true;
    }
            return false;
    }


    And this is my PlayerListener :

    Code:
    package me.Fredbuffer.Midas;
    
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerListener;
    
    public class MidasPlayerListener extends PlayerListener{
        private final Midas plugin;
        public MidasPlayerListener(Midas instance) {
            plugin = instance;
        }
        public void onPlayerInteract(PlayerInteractEvent event){
            Player player = event.getPlayer();
            if(plugin.oof == "on"){
                 if(event.getAction().equals(Action.LEFT_CLICK_BLOCK)){
                     Block block = event.getClickedBlock();
                     if(player.getItemInHand().getType() == Material.AIR) {
                         block.setType(Material.GOLD_BLOCK);
                         return;
                     }
                 }
             }
        }
    }
    i tested if turned isOP off, cause i use permissions but that also doesnt work :/

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

    nisovin

    You're trying to compare a lot of strings using == when you should be using .equals(). Also, I believe if you have nothing in your hand getType() will return null, not air. There are probably other small issues as well. Try using some printlns to figure out what's going on and what isn't working. Part of programming is learning to debug your code.
     
  15. Offline

    killerrj8

    well basically that with the getType() == Material.Air worked. It jsut doesnt cause the commands doesnt work good.
    And basically it has to work because i dont get any errors . And those "==" should work also.

    ok i tried with an Command executor but i get this error
    Code:
    [SEVERE] Error occurred while enabling Midas v1.3 (Is it up to date?): null
    java.lang.NullPointerException
        at me.Fredbuffer.Midas.Midas.onEnable(Midas.java:74)
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:125)
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:750)
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:253)
        at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:134)
        at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:112)
        at net.minecraft.server.MinecraftServer.e(MinecraftServer.java:232)
        at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:219)
        at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:146)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:285)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:422)
    at this Line

    Code:
    getCommand("Midas").setExecutor(new MidasCommands());
    I dont know why it gives me an error there

    Hmm lol i made a whole new plugin just to test if the commands work . Nothing else just a onEnable, onDisable and onCommand thing. There anywhere is the problem i dont know why but ALL the commands i enter doesnt get registered ... if i have permissions do i also need permission support

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

    DreadKyller

    ::Strings can not be compared using == == means you are comparing to see if the two are the same Object, look below:

    for example
    String[] test1= {"testing", "testing1"};
    String test2 = "testing";

    now both of the variables test2 and test1[0] have the same string stored, only they are two different object. The reason if mat = Material.BLAH is because getting the type returns a material object, meaning Material.STONE == Material.STONE, but in this case
    test1[0] != test2

    use string.equals(other_string) or equalsIgnoreCase if you want the command to be able to be typed in upper or lowercase letters. If you use == the command will almost never (if not never) return true on the if statements, and therefor will never do any of the content below the if. That's why it's not working. as @nisovin stated.

    also on the:

    Code:
    getCommand("Midas").setExecutor(new MidasCommands());
    it should be:

    Code:
    getCommand("Midas").setExecutor(new MidasCommands(this));
     
  17. Offline

    killerrj8

    im kinda confused. I used ur source of Fridges to test if that onCommand thing would work but it has the same effect. :/ It just dont shows anything i could even do something like that someone enters Test and a Text should appear . But even that simple Thing doesnt work. I never get anything :(
    DreadKyller can i some how contact u ? with skype or something else ?
     
  18. Offline

    DreadKyller

    I have xfire and you can PM me
     
Thread Status:
Not open for further replies.

Share This Page