NullPointerException (is it up to date)

Discussion in 'Plugin Development' started by tekkitbird, Sep 9, 2014.

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

    tekkitbird

    i am getting some error with making my plugin

    Log
    Code:
    [15:45:46] [Server thread/INFO]: [Brawl] Enabling Brawl vA_1.1
    [15:45:46] [Server thread/ERROR]: Error occurred while enabling Brawl vA_1.1 (Is it up to date?)
    java.lang.NullPointerException
        at me.AssaultBird2454.MG.MG.onEnable(MG.java:67) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:316) ~[server.jar:git-Spigot-1546]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:329) [server.jar:git-Spigot-1546]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [server.jar:git-Spigot-1546]
        at org.bukkit.craftbukkit.v1_7_R4.CraftServer.loadPlugin(CraftServer.java:476) [server.jar:git-Spigot-1546]
        at org.bukkit.craftbukkit.v1_7_R4.CraftServer.enablePlugins(CraftServer.java:394) [server.jar:git-Spigot-1546]
        at net.minecraft.server.v1_7_R4.MinecraftServer.n(MinecraftServer.java:360) [server.jar:git-Spigot-1546]
        at net.minecraft.server.v1_7_R4.MinecraftServer.g(MinecraftServer.java:334) [server.jar:git-Spigot-1546]
        at net.minecraft.server.v1_7_R4.MinecraftServer.a(MinecraftServer.java:290) [server.jar:git-Spigot-1546]
        at net.minecraft.server.v1_7_R4.DedicatedServer.init(DedicatedServer.java:210) [server.jar:git-Spigot-1546]
        at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:458) [server.jar:git-Spigot-1546]
        at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [server.jar:git-Spigot-1546]
    
    here is the line's around the error

    Code:java
    1. public void onEnable(){
    2.  
    3. if(new File(getDataFolder().toString()).exists()){
    4. log.info(ChatColor.GREEN + "Config File Found!");
    5. if (this.getConfig().getConfigurationSection("first_start").equals(true)) {
    6. first_start = true;
    7. this.getConfig().set("first_start", false);
    8. }
    9. }else if(!(new File(getDataFolder().toString()).exists())){
    10. this.saveDefaultConfig();
    11. }
    12.  
    13. Bukkit.getPluginManager().registerEvents(this, this);
    14.  
    15. LoadSB();
    16.  
    17. if(pm.getPlugin("MG Manager").isEnabled()) { //this is line 67
    18. System.out.println(); //This was to debug but was unable to debug
    19. log.info(ChatColor.GREEN + "The MG Manager is installed! Brawl will run when the MG manager starts Brawl.");
    20. log.warning(ChatColor.RED + "This version of Brawl does not support the MG Manager");
    21. Manager = true;
    22. }
    23. else {
    24. System.out.println(); //This was to debug but was unable to debug
    25. log.info(ChatColor.GREEN + "The MG Manager is not installed! Brawl will run its self or when a staff enables it");
    26. }
    27.  


    can some one please help me

    Reddeh

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

    bennie3211

    tekkitbird don't bump your thread within 24 hours please, second whats line 67 in your code?
     
  3. Offline

    tekkitbird

    i have it marked in the comment //this is line 67
     
  4. tekkitbird you are calling pm.getPlugin("MG Manager"); You should write the plugin into a variable and look if it is null, because i think it returns null for this name and you are trying to access the method isEnabled() on a empty object which throws a nullpointerexception. i hope you know that the name of the plugin is not the name of the jarfile? its name is the name which is written into the plugin.yml of the plugin
     
  5. Offline

    tekkitbird

    nevermind it is a signature
     
  6. tekkitbird instead of pm.getPlugin("MG Manager").isEnabled() you do it like this:
    Code:java
    1. Plugin p = pm.getPlugin("MG Manager");
    2. if(p!=null&&p.isEnabled()){
    3. // execute the rest of your code here
    4. }
     
  7. Offline

    tekkitbird

    here is the new error thanks for that

    Log
    Code:
    [18:42:09] [Server thread/INFO]: AssaultBird2454 issued server command: /mg brawl start
    [18:42:09] [Server thread/ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'mg' in plugin Brawl vA_1.1
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[server.jar:git-Spigot-1546]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:181) ~[server.jar:git-Spigot-1546]
        at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchCommand(CraftServer.java:767) ~[server.jar:git-Spigot-1546]
        at net.minecraft.server.v1_7_R4.PlayerConnection.handleCommand(PlayerConnection.java:1016) [server.jar:git-Spigot-1546]
        at net.minecraft.server.v1_7_R4.PlayerConnection.a(PlayerConnection.java:846) [server.jar:git-Spigot-1546]
        at net.minecraft.server.v1_7_R4.PacketPlayInChat.a(PacketPlayInChat.java:28) [server.jar:git-Spigot-1546]
        at net.minecraft.server.v1_7_R4.PacketPlayInChat.handle(PacketPlayInChat.java:65) [server.jar:git-Spigot-1546]
        at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:184) [server.jar:git-Spigot-1546]
        at net.minecraft.server.v1_7_R4.ServerConnection.c(ServerConnection.java:81) [server.jar:git-Spigot-1546]
        at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:731) [server.jar:git-Spigot-1546]
        at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:289) [server.jar:git-Spigot-1546]
        at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:584) [server.jar:git-Spigot-1546]
        at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:490) [server.jar:git-Spigot-1546]
        at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [server.jar:git-Spigot-1546]
    Caused by: java.lang.NullPointerException
        at me.AssaultBird2454.MG.MG.PICK_p1(MG.java:158) ~[?:?]
        at me.AssaultBird2454.MG.MG.prestart(MG.java:119) ~[?:?]
        at me.AssaultBird2454.MG.MG.onCommand(MG.java:246) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[server.jar:git-Spigot-1546]
        ... 13 more
    
    and the area around line 158, 119, 246

    error at 119
    Code:java
    1. public void prestart(){
    2. if(Bukkit.getOnlinePlayers().length == 2){
    3. P1_R = false;
    4. P2_R = false;
    5. PICK_p1(); //Line 119
    6. PICK_p2();
    7. waitingforserver();
    8. }


    error at 158

    Code:java
    1. public void PICK_p1() {
    2. Player player = Bukkit.getOnlinePlayers()[new Random().nextInt(Bukkit.getOnlinePlayers().length)];
    3. if(WAIT.hasPlayer(player)){ //line 158
    4. RED.addPlayer(player);
    5. P1_R = true;
    6. }else if(!(WAIT.hasPlayer(player))){
    7. PICK_p1();
    8. }
    9. }


    error at 246

    Code:java
    1. public boolean onCommand(CommandSender sender, Command command, String alias, String[] args) {
    2. if (alias.equalsIgnoreCase("mg")){
    3. //if(Manager = true){
    4.  
    5. //}else if(Manager = false){
    6. if(args.length == 1){
    7. sender.sendMessage(ChatColor.RED + "Sorry!!! Not Enough args");
    8. }else if(args.length == 2){
    9. if(args[0].equalsIgnoreCase("brawl")){
    10. if(args[1].equalsIgnoreCase("start")){
    11. prestart(); //line 246
    12. Bukkit.broadcastMessage(ChatColor.GREEN + "Minigame Brawl is now starting");
    13. }
    14. }
    15. }
    16. }
    17. //}
    18. return false;
    19. }
    20.  
     
  8. tekkitbird First, based on the inconsistencies and the fact that there are multiple places you don't obey convention, I'm guessing you're new to Java? You need to learn Java before you learn how to make plugins. I recommend the oracle tutorials or a Java book.

    Secondly, check the command name not the alias. Checking the alias would eliminate support for aliases. Thirdly, you never return in your command other than at the end. Finally, where is pm defined?
     
  9. Offline

    gyurix

    I learned the java from watching some tutorials how to make plugins, so now I understand these things, but why don't you try to find manually the problem instead of asking it in these forums? I always ask here thinks, that I really don't know how to start, not these errors.
    NullPointerException? Do you know what does it mean?
    Java generates this exception, when you want to call a method from null object. So you must be really carefull with the objects, and think, which object could be null.
    Back to this isEnabled method, where was your problem at the beginning:
    When you call the plugin manager-s getPlugin method, it can give you null, if the plugin doesn't exists. So you really must to be careful calling these methods, and before using them, you can check their javadoc, or check them for null using a simple if operator.
    I hope, that I helped you a bit.
     
  10. Offline

    Reddeh

    A'ight I'm here thanks to your calls \o3o/
    And then I see your problems are most likely solved by the other guy, so I'll leave you I suppose. But I'd recommend learning more than just that java, since it will definitely help. Buy a book, watch or read a tutorial. If you know your learning style, use it to your advantage to teach yourself Java.
     
  11. Offline

    SmooshCakez

    tekkitbird
    • NullPointerException because if you made a plugin called 'Hi there', you'd see 'Hi_there' in /pl. You can't have spaces in plugin names.
    • Use command.getName(), not commandLabel. If you use command label and do /pluginName:command, it'll return the usage. It'll work if you use command.getName().
    • Use getConfig().addDefault(path, value); don't check if the file exists and then set it.
     
  12. Offline

    tekkitbird

    SmooshCakez Thank you so much for the advice
    Reddeh That is OK have a good day
    gyurix I ask the forum for help and i learn from them so i dont make another mistake... i watch tutorials all the time so i am asking for help! not for people the code but if they tell me the code i will use it later when i need it so i learn it.
    AdamQpzm I have watched tutorials for both java and bukkit plugins... but no one knows everything and i am new but have been doing this for 10 months tho

    i will use the advice given and see what i get...
     
  13. Offline

    TGRHavoc

    Correct but, a Bukkit plugin developer knows both Java and the Bukkit API...
     
    Reddeh likes this.
  14. Offline

    tekkitbird

    TGRHavoc i know that is what i ment in my post

    is there anyone that is still able to help i am still geting Null pointer

    Code:
    [17:56:56] [Server thread/INFO]: AssaultBird2454 issued server command: /mg brawl start
    [17:56:56] [Server thread/ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'mg' in plugin Brawl vA_1.1
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[server.jar:git-Spigot-1546]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:181) ~[server.jar:git-Spigot-1546]
        at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchCommand(CraftServer.java:767) ~[server.jar:git-Spigot-1546]
        at net.minecraft.server.v1_7_R4.PlayerConnection.handleCommand(PlayerConnection.java:1016) [server.jar:git-Spigot-1546]
        at net.minecraft.server.v1_7_R4.PlayerConnection.a(PlayerConnection.java:846) [server.jar:git-Spigot-1546]
        at net.minecraft.server.v1_7_R4.PacketPlayInChat.a(PacketPlayInChat.java:28) [server.jar:git-Spigot-1546]
        at net.minecraft.server.v1_7_R4.PacketPlayInChat.handle(PacketPlayInChat.java:65) [server.jar:git-Spigot-1546]
        at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:184) [server.jar:git-Spigot-1546]
        at net.minecraft.server.v1_7_R4.ServerConnection.c(ServerConnection.java:81) [server.jar:git-Spigot-1546]
        at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:731) [server.jar:git-Spigot-1546]
        at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:289) [server.jar:git-Spigot-1546]
        at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:584) [server.jar:git-Spigot-1546]
        at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:490) [server.jar:git-Spigot-1546]
        at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [server.jar:git-Spigot-1546]
    Caused by: java.lang.NullPointerException
        at me.AssaultBird2454.MG.MG.prestart(MG.java:132) ~[?:?]
        at me.AssaultBird2454.MG.MG.onCommand(MG.java:277) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[server.jar:git-Spigot-1546]
        ... 13 more
    [17:57:02] [Server thread/INFO]: AssaultBird2454 lost connection: Disconnected
    
    Code:java
    1. public void prestart(){
    2. if(WAIT.getPlayers().size() >= 2){ //line 132
    3. P1R = false;
    4. P2R = false;
    5. PICKpa();
    6. PICKpb();
    7. waitingforserver();
    8. }else if(WAIT.getPlayers().size() <= 1){
    9. Bukkit.broadcastMessage(ChatColor.DARK_RED + "Not Enough Players to start a game");
    10. }else{
    11.  
    12. }
    13. }


    Code:
        public boolean onCommand(CommandSender sender, Command command, String string, String[] args) {
            if(command.getName().equalsIgnoreCase("mg")){
                //if(Manager = true){
     
                //}else if(Manager = false){
                    if(args.length == 1){
                        sender.sendMessage(ChatColor.RED + "Sorry!!! Not Enough args");
                    }else if(args.length == 2){
                        if(args[0].equalsIgnoreCase("brawl")){
                            if(args[1].equalsIgnoreCase("start")){
                                prestart(); //line 277
                                Bukkit.broadcastMessage(ChatColor.GREEN + "Minigame Brawl is now starting");
                            }
                        }
                    }
                }
            //}
            return false;
        }
    if no one wants to help that is ok

    also
    AdamQpzm
    i dont get what you mean by this

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

    tekkitbird

    bump please help me
     
  16. Offline

    Konato_K

    Your WAIT variable (or it's getPlayers() method) is null, you're probably never assigning it or something like that.
     
Thread Status:
Not open for further replies.

Share This Page