Solved NullpointerException onEnable

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

  1. Offline

    JoltTheBolt

    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:

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

    CraftCreeper6

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

    Strahan

    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

    JoltTheBolt

    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