Solved [Problem] NullPointerException without sense.

Discussion in 'Spigot Plugin Development' started by SrLegsini, May 29, 2016.

  1. I have a problem at my plugin, config and the inventories.

    Explanation:
    These are my inventories.
    Code (Text):
        Inventory staffInv = Bukkit.createInventory(null, 54, this.getConfig().getString("GUI.MenuName"));
        Inventory optionsMenu = Bukkit.createInventory(null, 54, this.getConfig().getString("GUI.OptionsAndStatsMenuName"));
    When I load them, I receive an error in the console.
    Yep, the NullPointerException referring to the "this.getConfig()".

    All config is perfect, and if you want, here's the full code:
    (The inventories are at the line 735 & 736)

    https://github.com/MrLechuga/SimpleStaffControl2/blob/master/MClass.java

    [​IMG]

    I'll give you a potato if you help me! :)
     
  2. Your Like 335:

    p.openInventory(staffInv);

    Probably your "staffinv", is null.
     
  3. It's not. I tested using strings without getting it from config, and it works at this way, but I want that the user can config the menu name.
    Example:
    Code (Text):
    Inventory staffInv = Bukkit.createInventory(null, 54, "Staff List!";
     
  4. Than the config is null or the path is null.
     
  5. Reload the page, I edited that reply.
    And the path/config isn't null. I used /test commands that gives me all paths, and all works fine :p
     
  6. Hours searching, and no one knows why the problem is happening...

    P.S. Sorry if my english sucks.
     
  7. @SrLegsini your error doesn't match your code (there could be no NPE on the line 335). Rebuild your jar, restart your server, and test again.
     
  8. The problem is the following:
    I re-written my code 3 times for the same error.
    I used different ways to fix it, like making methods for the strings

    I don't know what to do :(
     
  9. Like in the title...
    It has no sense.
     
  10. There's a way to change an inventory's name?
    If it's, I can test editing it when a player opens it.
     
  11. Move the initialization of the two inventories to inside the onEnable() method
    Code (Text):

    Inventory staffInv = Bukkit.createInventory(null, 54, this.getConfig().getString("GUI.MenuName"));
    Inventory optionsMenu = Bukkit.createInventory(null, 54, this.getConfig().getString("GUI.OptionsAndStatsMenuName"));
     
    make it
    Code (Text):

    Inventory staffInv = null;
    Inventory optionsMenu = null;

    @Override
    public void onEnable() {
        //save config, etc.
        staffInv = Bukkit.createInventory(null, 54, this.getConfig().getString("GUI.MenuName"));
        optionsMenu = Bukkit.createInventory(null, 54, this.getConfig().getString("GUI.OptionsAndStatsMenuName"));
    }
     
     
    • Winner Winner x 1