Solved JavaPlugin NullPointerException help!

Discussion in 'Spigot Plugin Development' started by chunza2542, May 6, 2017.

  1. I trying to make shop plugin call "Shopman" but when I ran the server. I got something wrong.

    Here is my err code:
    Code (Text):
    [08:00:57 ERROR]: Error occurred while enabling Shopman v1.0.0 (Is it up to date?)
        at me.chunza2542.shopman.listener.ShopmanInventory.renderInventoryShop( ~[?:?]
        at me.chunza2542.shopman.listener.ShopmanInventory.<init>( ~[?:?]
        at me.chunza2542.shopman.Shopman.onEnable( ~[?:?]
        at ~[spigot.jar:git-Spigot-7d15d07-c194444]
        at [spigot.jar:git-Spigot-7d15d07-c194444]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin( [spigot.jar:git-Spigot-7d15d07-c194444]
        at org.bukkit.craftbukkit.v1_9_R1.CraftServer.loadPlugin( [spigot.jar:git-Spigot-7d15d07-c194444]
        at org.bukkit.craftbukkit.v1_9_R1.CraftServer.enablePlugins( [spigot.jar:git-Spigot-7d15d07-c194444]
        at org.bukkit.craftbukkit.v1_9_R1.CraftServer.reload( [spigot.jar:git-Spigot-7d15d07-c194444]
        at org.bukkit.Bukkit.reload( [spigot.jar:git-Spigot-7d15d07-c194444]
        at org.bukkit.command.defaults.ReloadCommand.execute( [spigot.jar:git-Spigot-7d15d07-c194444]
        at org.bukkit.command.SimpleCommandMap.dispatch( [spigot.jar:git-Spigot-7d15d07-c194444]
        at org.bukkit.craftbukkit.v1_9_R1.CraftServer.dispatchCommand( [spigot.jar:git-Spigot-7d15d07-c194444]
        at org.bukkit.craftbukkit.v1_9_R1.CraftServer.dispatchServerCommand( [spigot.jar:git-Spigot-7d15d07-c194444]
        at net.minecraft.server.v1_9_R1.DedicatedServer.aL( [spigot.jar:git-Spigot-7d15d07-c194444]
        at net.minecraft.server.v1_9_R1.DedicatedServer.D( [spigot.jar:git-Spigot-7d15d07-c194444]
        at net.minecraft.server.v1_9_R1.MinecraftServer.C( [spigot.jar:git-Spigot-7d15d07-c194444]
        at [spigot.jar:git-Spigot-7d15d07-c194444]
        at [?:1.7.0_79]
    Here is my Main JavaPlugin class,
    shopmanInventory I put this (Shopman) into constructor method.

    And Here is my When I put the highlighted line into my code It shows me an error. But when I change it to shopman.getLogger().info("YAY"); It does not have any error show in the console.

    How can I fix this, thx!

    Attached Files:

  2. That line highlighted is line 31, correct? If so, print in console every object you get (shopman, getShopmanDatabase, etc.) to see what is null.
  3. @RubbaBoy getShopmanDatabase is null but shopman isn't. I think shopman = plugin not = shopman. because when I getLogger is doesn't have any err.
  4. It is most likely the order you are initializing things in. In your onEnable make sure that you register your event class after you initialize your variables in your onEnable.
    • Informative Informative x 1
  5. call registerDataBase first. The shopmanDatabase or whatever is still null at this point so you need to initialise it.
    • Agree Agree x 1
  6. Thx! It's now working!