NullPointerException

Discussion in 'Plugin Development' started by henne90gen, Jun 26, 2012.

  1. Offline

    henne90gen

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Hello
    I tried to make a plugin that adds something on signs.
    My problem is that I cant enable the plugin because of a NullPointerException-Error.
    Here the errorcode:
    Code:
    2012-06-26 23:04:55 [INFO] [SignNews] Enabling SignNews v0.1
    2012-06-26 23:04:55 [SEVERE] Error occurred while enabling SignNews v0.1 (Is it up to date?)
    java.lang.NullPointerException
    at com.github.henne90gen.SignNews.onEnable(SignNews.java:25)
    at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:215)
    at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:337)
    at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:381)
    at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:256)
    at org.bukkit.craftbukkit.CraftServer.enablePlugins(CraftServer.java:238)
    at net.minecraft.server.MinecraftServer.t(MinecraftServer.java:381)
    at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:368)
    at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:197)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:432)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    Here are the other files of my plugin:
    MainFile:
    Code:
    package com.github.henne90gen;
     
    import java.util.logging.Logger;
     
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.Configuration;
    import org.bukkit.entity.Player;
    import org.bukkit.event.block.Action;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class SignNews extends JavaPlugin{
     
    Logger log = Logger.getLogger("Minecraft");
     
    public SignNewsCommands sncmd;
    Config config;
     
    String px = ChatColor.AQUA+"[SignNews] "+ChatColor.WHITE;
     
    public void onEnable(){
    //Befehle
    sncmd = new SignNewsCommands(this);
    getCommand("signnews").setExecutor(sncmd);
     
    //Config
    config = new Config(this);
     
    log.info("SignNews enabled!");
    }
     
    public void onDisable(){
    this.saveConfig();
    log.info("SignNews disabled!");
    }
    }
    CommandFile:
    Code:
    package com.github.henne90gen;
     
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.Configuration;
    import org.bukkit.entity.Player;
    import org.bukkit.event.block.Action;
    import org.bukkit.inventory.ItemStack;
     
    public class SignNewsCommands implements CommandExecutor {
     
    SignNews plg;
    String px;
     
    public SignNewsCommands (SignNews plg) {
    this.plg = plg;
    this.px = plg.px;
    }
     
    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (sender instanceof Player) {
    Player p = (Player) sender;
     
    //Spielerbefehl "/setsignnews ohne Argumnte
    if (args.length < 1) {
    if (cmd.getName().equalsIgnoreCase("signnews")) {
    p.sendMessage(ChatColor.RED + "Diese Argumente kannst du verwenden:");
    p.sendMessage(ChatColor.RED + "create  Eine neue News-Wand erstellen");
    }
    } else {
    if (args.length == 1) return ExecuteCmd(p, args[0]);
    if (args.length == 2) return ExecuteCmd(p, args[0], args[1]);
    if (args.length == 3) return ExecuteCmd(p, args[0], args[1], args[2]);
    }
    }
    return false;
    }
     
    public boolean ExecuteCmd(Player p, String cmd) {
    return false;
    }
     
    public boolean ExecuteCmd(Player p, String cmd, String arg) {
    return false;
    }
     
    public boolean ExecuteCmd(Player p, String cmd, String arg1, String arg2) {
    return false;
    }
     
    }
    ConfigFile:
    Code:
    package com.github.henne90gen;
     
    import org.bukkit.configuration.Configuration;
    import org.bukkit.event.block.Action;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Config {
    private SignNews plugin;
    private Configuration config;
    public String msg1, msg2, msg3;
    public boolean invertMouse;
    public Action clickAktion;
     
    public Config(SignNews plugin) {
    this.plugin = plugin;
    config = plugin.getConfig().getRoot();
    config.options().copyDefaults(true);
    plugin.saveConfig();
    getOpts();
    }
    public void getOpts() {
    msg1 = "Config.messages.broadcast1";
    msg2 = "Config.messages.broadcast2";
    msg3 = "Config.messages.broadcast3";
     
    }
    }
    plugin.yml
    Code:
    name: SignNews
    version: 0.1
    description: Post something new on your sign!
    author: henne90gen
    website:  http://bukkit.org/
     
    main: com.github.henne90gen.SignNews
     
    commands:
    I did not added the commands so far.

    PS: Sorry for my bad english I'm german

    This post has been edited 1 time. It was last edited by henne90gen Jun 26, 2012.
  2. Offline

    Dreeass

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    What line has number 25, and learn Java before you make a plugin.
  3. Offline

    henne90gen

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME

    Thanks for your answer!
    line number 25 is:
    getCommand("signnews").setExecutor(sncmd);

  4. Offline

    Dreeass

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Don't do the sncmd but write it full and do you have a constructor in the class that has to execute the command?
  5. Offline

    henne90gen

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    The code I posted above was all I have in my plugin.
    So can you look through it? Im a beginner so I dont know what you mean with "constructor" Im sorry.
    The first thing you said was something with write full so what is "full" for you?
  6. Offline

    r0306

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    @henne90gen
    Dreeass is asking whether you put a reference to your main class in your command executor. If so, you need to add the argument of (this) when registering your command.

    This post has been edited 1 time. It was last edited by r0306 Jun 26, 2012.
  7. Offline

    henne90gen

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Like this:
    getCommand("signnews").setExecutor(this.sncmd);
  8. Offline

    Pandemoneus

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Nope, that's not what a constructor is.
    A constructor is a specific method that is called when you use
    Code:java
    1.  
    2. new MyClass(...)
    3.  


    More info: http://www.javabeginner.com/learn-java/java-constructors

    [edit]
    @henne90gen
    The reason why you are getting a NullPointerException is because you want to register the command "signnews" which you never defined in your plugin.yml

    This post has been edited 1 time. It was last edited by Pandemoneus Jun 26, 2012.
    Codex Arcanum and henne90gen like this.
  9. Offline

    henne90gen

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    mmh ;) thanks alot!
    I thought: "Oh lets do that later." and now I stand there dumb.
    Now everything is running correct!
    Thanks
  10. Offline

    r0306

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    @Pandemoneus
    Oh. I'm wrong then. I got it mixed up with parameter. :(

Share This Page