Solved NullpointerException onEnable

Discussion in 'Plugin Development' started by JoltTheBolt, Mar 26, 2022.

  1. Offline


    Uhm, I think I am making a common mistake but I don't know. My brain is also not at full capacity right now. Thanks for any help.

    Error occurred while enabling LaserTag v1.0 (Is it up to date?)
            at io.github.JoltMuz.LazerTag.main.onEnable( ~[?:?]
            at ~[server.jar:git-Spigot-db6de12-18fbb24]
            at [server.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin( [server.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin( [server.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins( [server.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.s( [server.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.k( [server.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.a( [server.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.DedicatedServer.init( [server.jar:git-Spigot-db6de12-18fbb24]
            at [server.jar:git-Spigot-db6de12-18fbb24]
            at Source) [?:1.8.0_51]
    Caused by: java.lang.NullPointerException
            at io.github.JoltMuz.LazerTag.UI.<clinit>( ~[?:?]
            ... 12 more
    Line 27 of
    LongRangeSelect.getItemMeta().getLore().add(ChatColor.YELLOW + "Shoot a laser with increased range");
    Line 11 of
    getServer().getPluginManager().registerEvents(new UI(), this);
  2. Offline


    Could be 3 things,
    LongRangeSelect is null
    getItemMeta() is null
    getLore() is null
  3. Offline


    This is why I don't like hanging methods off of things that are nullable. You should always assume the data is bad and code accordingly.
  4. Offline


    Ah, I got it. Thank you very much. I guess my past energetic self was ready to take risks with the shortcut with the ItemStack, meta and lore but my current self wasn't able to face it XD

    Yeah I agree XD

Share This Page