NullPointerException

Discussion in 'Plugin Development' started by Samthelord1, Jan 1, 2015.

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

    Samthelord1

    Code:
    01.01 17:48:03 [Server] INFO ... 13 more
    01.01 17:48:03 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 17:48:03 [Server] INFO at me.samthelord1.tokens.Main.onCommand(Main.java:94) ~[?:?]
    01.01 17:48:03 [Server] INFO Caused by: java.lang.NullPointerException
    01.01 17:48:03 [Server] INFO at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 17:48:03 [Server] INFO at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:469) [craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 17:48:03 [Server] INFO at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:558) [craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 17:48:03 [Server] INFO at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:258) [craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 17:48:03 [Server] INFO at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:667) [craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 17:48:03 [Server] INFO at net.minecraft.server.v1_7_R4.ServerConnection.c(SourceFile:134) [craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 17:48:03 [Server] INFO at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:157) [craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 17:48:03 [Server] INFO at net.minecraft.server.v1_7_R4.PacketPlayInChat.handle(PacketPlayInChat.java:47) [craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 17:48:03 [Server] INFO at net.minecraft.server.v1_7_R4.PacketPlayInChat.a(PacketPlayInChat.java:28) [craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 17:48:03 [Server] INFO at net.minecraft.server.v1_7_R4.PlayerConnection.a(PlayerConnection.java:818) [craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 17:48:03 [Server] INFO at net.minecraft.server.v1_7_R4.PlayerConnection.handleCommand(PlayerConnection.java:957) [craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 17:48:03 [Server] INFO at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchCommand(CraftServer.java:740) ~[craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 17:48:03 [Server] INFO at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:180) ~[craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 17:48:03 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit_dev_3116.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    01.01 17:48:03 [Server] INFO org.bukkit.command.CommandException: Unhandled exception executing command 'tokens' in plugin Tokens v1.0.0
    01.01 17:48:03 [Server] ERROR null
    getting this, line 94 in Main class;
    menu.show(p);

    Whole onCommand section;
    Code:
    @Override
       public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
       if(cmd.getLabel().equalsIgnoreCase("tokens")) {
    
          
          
           if(!(sender instanceof Player)) {
              sender.sendMessage("You must be a player to perform this command!");
          }
          if(sender instanceof Player) {
            
              if(args.length == 0) {
                  sender.sendMessage(ChatColor.GOLD + "========[TokenShop]========");
                  sender.sendMessage(ChatColor.GOLD + "[TokenShop]" + ChatColor.GREEN + "</tokens balance> - Displays how many tokens you have.");
                  sender.sendMessage(ChatColor.GOLD + "[TokenShop]" + ChatColor.GREEN + "</tokens shop> - Opens the token shop.");
              }
                  if(args.length >= 2) {
                  sender.sendMessage(ChatColor.GOLD + "========[TokenShop]========");
                  sender.sendMessage(ChatColor.GOLD + "[TokenShop]" + ChatColor.GREEN + "</tokens balance> - Displays how many tokens you have.");
                  sender.sendMessage(ChatColor.GOLD + "[TokenShop]" + ChatColor.GREEN + "</tokens shop> - Opens the token shop.");
                 
             
              }
              if(args.length == 1) {
                 
              Player p = (Player) sender;
              if(args[0].equalsIgnoreCase("balance")) {
                p.sendMessage(ChatColor.GOLD + "[TokenShop]" + ChatColor.GREEN + "you have " + getConfig().getInt("tokens." + p.getName()) + "."); 
              }
              if(args[0].equalsIgnoreCase("shop")) {
                  menu.show(p);
                
              }
                 
             
          }
          }
       }
       return true;
       }
     
  2. Offline

    drpk

  3. Offline

    zurg200

    The error is on line 94 I think.. Try looking at it.. U should try putting return true; on the bottom of the end of the command.. Just a suggestion.. And did u make the menu? And correctly set the slots??
     
  4. Offline

    Samthelord1

    @drpk
    public void show(Player p) {
    p.openInventory(inv);
    }
     
    moo3oo3oo3 likes this.
  5. Offline

    drpk

  6. Offline

    Samthelord1

    @drpk create inv here;
    public Inventory inv;

    add itemstacks to inv here;
    inv.setItem(0, sgapple);
    inv.setItem(1, lbow);
    inv.setItem(2, laxe);
    inv.setItem(3, lsword);
    inv.setItem(4, lshovel);
    inv.setItem(5, lpickaxe);
    inv.setItem(6, creeperegg);
    inv.setItem(7, hopper);
    inv.setItem(8, beacon);

    @drpk checked if !inv == null, still getting the error.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 31, 2016
    moo3oo3oo3 likes this.
  7. Offline

    Rocoty

    menu is null. Given the code you have provided and the stack trace, there can be no other cause.
     
  8. Offline

    teej107

Thread Status:
Not open for further replies.

Share This Page