Enable Error

Discussion in 'Spigot Plugin Development' started by Gargant0373, Jan 14, 2019.

  1. So I have an error in the code somewhere.
    The error:
    Code (Text):
    java.lang.ExceptionInInitializerError: null
            at Main.Main.onEnable(Main.java:8) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264) ~[spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:337) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:403) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugin(CraftServer.java:381) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugins(CraftServer.java:330) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at net.minecraft.server.v1_12_R1.MinecraftServer.t(MinecraftServer.java:422) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at net.minecraft.server.v1_12_R1.MinecraftServer.l(MinecraftServer.java:383) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at net.minecraft.server.v1_12_R1.MinecraftServer.a(MinecraftServer.java:338) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at net.minecraft.server.v1_12_R1.DedicatedServer.init(DedicatedServer.java:272) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:545) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_191]
    Caused by: java.lang.NullPointerException
            at Main.globals.<clinit>(globals.java:7) ~[?:?]
            ... 12 more
    Main:
    Code (Java):
    package Main;

    import org.bukkit.plugin.java.JavaPlugin;

    public class Main extends JavaPlugin{
       
        public void onEnable() {
            globals.mains = this;
            Setup.runEverything();
        }
    }
     
    Setup:
    Code (Java):
    package Main;

    import PickaxeShit.givePick;
    import PickaxeShit.pickEvents;

    public class Setup {
        public static void Listeners() {
            globals.mains.getServer().getPluginManager().registerEvents(new pickEvents(), globals.mains);
            globals.mains.getServer().getPluginManager().registerEvents(new givePick(), globals.mains);
        }
        public static void Commands() {
           
        }
        public static void Globals() {
           
        }
        public static void Config() {
            globals.mains.saveDefaultConfig();
        }
        public static void runEverything() {
            Listeners();
            Commands();
            Globals();
            Config();
        }
    }
     
     
  2. foncused

    Moderator Patron

    Few things here:
    • Package names should be lowercase (e.g. me.gargant0373.plugin.main)
    • Class names should be CamelCase
    • Method and variable names should be mixedCase
    Generally speaking, it is not a good idea to have public class variables unless they are finalized. The better option is to make them private and provide access and mutate methods (getters/setters) when they are needed.

    That being said, your NPE is occurring inside the globals.java class and is due to an initialization issue (accessed before being assigned a value).
     
    • Agree Agree x 1
  3. I still do not understand, what do I need to do?
     
  4. your globals variable is null,
    where do you define that and do you initialize it?
     
  5. I can’t see a variable called globals so how did you add it?

    Learn java is my only advice ;)
     
  6. I guess globals is another class with static abuse


    A tip:
    The main class is usually the class where one should do the setup.
    Don't put that into another class.
     
  7. I had globals initialized in a separate class...
     
  8. Okay if you initialized it in another class then you need to pass that instance of it to wherever you are using it,
    As a heads up, You should do all initizalation in your main class anyway (Or create a Util class and use it for all of that and just initialize the rest in the constucter of util)
    Etherway you clearly lack knowlage in this field so id suggest learning more java before attempting this again
     
  9. Please learn java convention. Foncused said it too.
    You need to change tout Package.Name to package.name, your className to ClassName and your MethodName to methodName
     

Share This Page