Solved Need Help debugging this

Discussion in 'Plugin Development' started by DividedByZero, Jul 30, 2014.

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

    DividedByZero

    Ik i am kinda a noob at coding but this will help me learn so try to explain this error and teach me good habbits.

    Code:
    [18:29:14 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'ads'
    in plugin AdvancedSettings v1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[ser
    ver.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:18
    0) ~[server.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
            at org.bukkit.craftbukkit.v1_7_R3.CraftServer.dispatchCommand(CraftServe
    r.java:701) ~[server.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
            at net.minecraft.server.v1_7_R3.PlayerConnection.handleCommand(PlayerCon
    nection.java:956) [server.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
            at net.minecraft.server.v1_7_R3.PlayerConnection.a(PlayerConnection.java
    :817) [server.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
            at net.minecraft.server.v1_7_R3.PacketPlayInChat.a(PacketPlayInChat.java
    :28) [server.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
            at net.minecraft.server.v1_7_R3.PacketPlayInChat.handle(PacketPlayInChat
    .java:47) [server.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
            at net.minecraft.server.v1_7_R3.NetworkManager.a(NetworkManager.java:157
    ) [server.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
            at net.minecraft.server.v1_7_R3.ServerConnection.c(SourceFile:134) [serv
    er.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
            at net.minecraft.server.v1_7_R3.MinecraftServer.v(MinecraftServer.java:6
    67) [server.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
            at net.minecraft.server.v1_7_R3.DedicatedServer.v(DedicatedServer.java:2
    60) [server.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
            at net.minecraft.server.v1_7_R3.MinecraftServer.u(MinecraftServer.java:5
    58) [server.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
            at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java
    :469) [server.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
            at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:6
    28) [server.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    Caused by: java.lang.NullPointerException
            at org.advancedsettings.IconMenu.IconMenu.<init>(IconMenu.java:34) ~[?:?
    ]
            at org.advancedsettings.Api.SettingsMenuApi.openMenu(SettingsMenuApi.jav
    a:14) ~[?:?]
            at org.advancedsettings.Commands.Commands.onCommand(Commands.java:39) ~[
    ?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[ser
    ver.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
            ... 13 more
    Commands.java
    Code:java
    1. public class Commands implements CommandExecutor {
    2. private final AdvancedSettings plugin;
    3.  
    4. public Commands(AdvancedSettings plugin) {
    5. this.plugin = plugin;
    6. }
    7.  
    8. SettingsMenuApi settingsmenuapi = new SettingsMenuApi(this.plugin);
    9.  
    10. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    11. if(!(sender instanceof Player)) {
    12. Bukkit.getLogger().log(Level.WARNING, "Please do not execute commands through the console.");
    13. return false;
    14. }
    15.  
    16. Player player = (Player) sender;
    17.  
    18. if(cmd.getName().equalsIgnoreCase("advancedsettings") || cmd.getName().equalsIgnoreCase("ads")) {
    19. if(args.length == 0) {
    20. if(!player.hasPermission("advancedsettings.openmenu")) {
    21. player.sendMessage(Messages.noperms);
    22. return false;
    23. }
    24.  
    25. settingsmenuapi.openMenu(player);
    26. }
    27. else if(args[0].equalsIgnoreCase("help")) {
    28. if(!player.hasPermission("advancedsettings.help")) {
    29. player.sendMessage(Messages.noperms);
    30. return false;
    31. }
    32. player.sendMessage(ChatColor.GREEN+"======="+ChatColor.AQUA+" Advanced"+ChatColor.BLUE+"Settings "+ChatColor.GREEN+"=======");
    33. player.sendMessage(ChatColor.GRAY+"Created by HiROs15");
    34. player.sendMessage("");
    35. player.sendMessage(ChatColor.WHITE+"/advancedsettings - "+ChatColor.GOLD+"Open your settings menu.");
    36. player.sendMessage(ChatColor.GREEN+"==============================");
    37.  
    38. return false;
    39. }
    40. return false;
    41. }
    42.  
    43. return false;
    44. }
    45. }
    46.  


    SettingsMenuApi.java

    Code:java
    1. public class SettingsMenuApi {
    2. private Plugin plugin;
    3. public SettingsMenuApi(Plugin plugin) {
    4. this.plugin = plugin;
    5. }
    6.  
    7. public void openMenu(Player player) {
    8. IconMenu adsmenu = new IconMenu(9, "Test", new IconMenu.OptionClickEventHandler() {
    9. @Override
    10. public void onOptionClick(IconMenu.OptionClickEvent event) {
    11.  
    12. }
    13. }, plugin);
    14.  
    15. adsmenu.open(player);
    16. }
    17. }
    18.  


    Could you please tell me what is going on. And EXPLAIN to me why this is happing and to help me in the future.
     
  2. Offline

    techboy291

    According to the stack trace, the problem originated in IconMenu at line 34. Could you show us that class please?
     
  3. Offline

    DividedByZero

    Code:java
    1. public class IconMenu implements Listener {
    2.  
    3. private String name;
    4. private int size;
    5. private OptionClickEventHandler handler;
    6. private Plugin plugin;
    7.  
    8. private String[] optionNames;
    9. private ItemStack[] optionIcons;
    10.  
    11. public IconMenu(int size, String name, OptionClickEventHandler handler, Plugin plugin) {
    12. this.name = name;
    13. this.size = size;
    14. this.handler = handler;
    15. this.plugin = plugin;
    16. this.optionNames = new String[size];
    17. this.optionIcons = new ItemStack[size];
    18. plugin.getServer().getPluginManager().registerEvents(this, plugin);
    19. }
    20.  
    21. public IconMenu setOption(int position, ItemStack icon, String name, String... info) {
    22. optionNames[position] = name;
    23. optionIcons[position] = setItemNameAndLore(icon, name, info);
    24. return this;
    25. }
    26.  
    27. public void open(Player player) {
    28. Inventory inventory = Bukkit.createInventory(player, size, name);
    29. for (int i = 0; i < optionIcons.length; i++) {
    30. if (optionIcons[i] != null) {
    31. inventory.setItem(i, optionIcons[i]);
    32. }
    33. }
    34. player.openInventory(inventory);
    35. }
    36.  
    37. public void destroy() {
    38. HandlerList.unregisterAll(this);
    39. handler = null;
    40. plugin = null;
    41. optionNames = null;
    42. optionIcons = null;
    43. }
    44.  
    45. @EventHandler(priority=EventPriority.MONITOR)
    46. void onInventoryClick(InventoryClickEvent event) {
    47. if (event.getInventory().getTitle().equals(name)) {
    48. event.setCancelled(true);
    49. int slot = event.getRawSlot();
    50. if (slot >= 0 && slot < size && optionNames[slot] != null) {
    51. Plugin plugin = this.plugin;
    52. OptionClickEvent e = new OptionClickEvent((Player)event.getWhoClicked(), slot, optionNames[slot]);
    53. handler.onOptionClick(e);
    54. if (e.willClose()) {
    55. final Player p = (Player)event.getWhoClicked();
    56. Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
    57. public void run() {
    58. p.closeInventory();
    59. }
    60. }, 1);
    61. }
    62. if (e.willDestroy()) {
    63. destroy();
    64. }
    65. }
    66. }
    67. }
    68.  
    69. public interface OptionClickEventHandler {
    70. public void onOptionClick(OptionClickEvent event);
    71. }
    72.  
    73. public class OptionClickEvent {
    74. private Player player;
    75. private int position;
    76. private String name;
    77. private boolean close;
    78. private boolean destroy;
    79.  
    80. public OptionClickEvent(Player player, int position, String name) {
    81. this.player = player;
    82. this.position = position;
    83. this.name = name;
    84. this.close = true;
    85. this.destroy = false;
    86. }
    87.  
    88. public Player getPlayer() {
    89. return player;
    90. }
    91.  
    92. public int getPosition() {
    93. return position;
    94. }
    95.  
    96. public String getName() {
    97. return name;
    98. }
    99.  
    100. public boolean willClose() {
    101. return close;
    102. }
    103.  
    104. public boolean willDestroy() {
    105. return destroy;
    106. }
    107.  
    108. public void setWillClose(boolean close) {
    109. this.close = close;
    110. }
    111.  
    112. public void setWillDestroy(boolean destroy) {
    113. this.destroy = destroy;
    114. }
    115. }
    116.  
    117. private ItemStack setItemNameAndLore(ItemStack item, String name, String[] lore) {
    118. ItemMeta im = item.getItemMeta();
    119. im.setDisplayName(name);
    120. im.setLore(Arrays.asList(lore));
    121. item.setItemMeta(im);
    122. return item;
    123. }
    124.  
    125. }[/i][/i]
     
  4. Offline

    techboy291

    Actually, I'd suggest reading this.
     
  5. Offline

    ulsa

    well it cant open inventory becouse inventory is null so i would suggest checking if its null or not before executing that command
     
  6. Offline

    DividedByZero

    Ik how to read errors i just cant seem to fix it. It has something to do with my SettingsMenuApi file. The plugin value is throwing the null error. but when i put openMenu() code directly into the command handler it works fine.
     
  7. Offline

    techboy291

    The inventory was just set using Bukkit.createInventory() though, so I don't think it could have been null. Also,

    Code:
    player.openInventory(inventory);
    
    isn't actually line 34, because he's not pasting the whole class (he left out the imports and the package declaration).
     
    MrSparkzz likes this.
  8. Offline

    MrSparkzz

    ulsa DividedByZero
    You need to post the whole class. You are missing your imports and package label, which count as lines.

    EDIT: Sniped by techboy291
     
    techboy291 likes this.
  9. Offline

    DividedByZero

    i fixed it.
     
Thread Status:
Not open for further replies.

Share This Page