NullPointerException

Discussion in 'Plugin Development' started by vasil7112, Sep 1, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    vasil7112

    Dear Developers,
    I cannot find that null in my Plugin:/
    Error
    Code:
    [SEVERE] Error occurred while enabling MGCORE v1.0 (Is it up to date?)
    java.lang.NullPointerException
        at me.vasil7112.MGCORE.Main.onEnable(Main.java:65)
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:217)
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:457)
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:382)
        at org.bukkit.craftbukkit.v1_6_R2.CraftServer.loadPlugin(CraftServer.java:286)
        at org.bukkit.craftbukkit.v1_6_R2.CraftServer.enablePlugins(CraftServer.java:268)
        at net.minecraft.server.v1_6_R2.MinecraftServer.l(MinecraftServer.java:319)
        at net.minecraft.server.v1_6_R2.MinecraftServer.f(MinecraftServer.java:296)
        at net.minecraft.server.v1_6_R2.MinecraftServer.a(MinecraftServer.java:256)
        at net.minecraft.server.v1_6_R2.DedicatedServer.init(DedicatedServer.java:164)
        at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:397)
        at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582)
    Main
    Code:java
    1. public class Main extends JavaPlugin implements Listener{
    2. public Main plugin;
    3. public ConfigSetup configSetup; //ADDING ConfigSetup instance!
    4. public PlayerAPI playerAPI;
    5. public Integer Time = 5;
    6. public String header = ChatColor.GOLD + "======================[" + ChatColor.GREEN + "MC-MG" + ChatColor.GOLD + "]======================";
    7. public String miniheader = ChatColor.GOLD + "[" + ChatColor.GREEN + "MC-MG" + ChatColor.GOLD + "]";
    8. public Location loc;
    9. public Boolean canJoin;
    10. final Random random = new Random();
    11.  
    12. public String currentmap;
    13. public String currentmg;
    14. public String currentdesc;
    15. public String milink;
    16. public void onEnable(){
    17. plugin = this;
    18. getLogger().log(Level.INFO, "Enabled");
    19. //Bukkit.createWorld(new WorldCreator("WipeOut"));
    20. Bukkit.createWorld(new WorldCreator("DeathSwap"));
    21. //Bukkit.createWorld(new WorldCreator("Example"));
    22. //Bukkit.createWorld(new WorldCreator("HungerGames"));
    23. //Bukkit.createWorld(new WorldCreator("JailBrake"));
    24. Bukkit.createWorld(new WorldCreator("Knife"));
    25. Bukkit.createWorld(new WorldCreator("Gravitron"));
    26. Bukkit.createWorld(new WorldCreator("Build My Thing"));
    27. //Bukkit.createWorld(new WorldCreator("Paintball"));
    28.  
    29.  
    30. PluginManager pm = getServer().getPluginManager();
    31. pm.registerEvents(this, this);
    32. pm.registerEvents(new PlayerListener(plugin), this);
    33. pm.registerEvents(new ServerListener(plugin), this);
    34. pm.registerEvents(new CreatureListener(plugin), this);
    35. //pm.registerEvents(new TabApiListener(), this);
    36. pm.registerEvents(new BlockListener(plugin), this);
    37. pm.registerEvents(new ConfigSetup(plugin), this);
    38.  
    39. configSetup.setupConfig(); //ERROR LINE
    40.  

    API
    Code:java
    1. package me.vasil7112.MGCORE.api;
    2.  
    3. import me.vasil7112.MGCORE.Main;
    4.  
    5. import org.bukkit.configuration.file.FileConfiguration;
    6. import org.bukkit.event.Listener;
    7. public final class ConfigAPI{
    8. public Main plugin;
    9. //private ConfigAPI() {}
    10. public ConfigAPI ConfigAPIInstance;
    11.  
    12. public void onEnable(){
    13. ConfigAPIInstance = this;
    14. }
    15.  
    16. public FileConfiguration getConfig(){
    17. return plugin.getConfig();
    18. }
    19.  
    20. }

    It might be a really silly mistake, but i can't trace it:/
    The problem was caused because i needed to remove all Static from my Apis and Listeners so i won't get the 'Cannot Respawn Bug' http://forums.bukkit.org/threads/players-cant-respawn.171376/
     
  2. Offline

    metalhedd

    at me.vasil7112.MGCORE.Main.onEnable(Main.java:65)

    which line is 65 of Main.java?

    Nevermind, just saw your comment. configSetup is null because you never set it anywhere.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  3. Offline

    vasil7112

    configSetup.setupConfig();//ERROR LINE

    If you would read the Main Code, you would see that i've added the Error Line:) And also that i've added the Instance, public ConfigSetup configSetup;
     
  4. Offline

    metalhedd


    If you knew what line the error was on, how can you not be able to solve this yourself? there is only one variable on that line, it's the one that's null, there's no other possibility.
     
  5. Offline

    vasil7112

    I know what line is the problem at, but i don't understand why it is null, while i set ConfigSetup to be configSetup at the begging
     
  6. Offline

    metalhedd


    you didn't give it any value, so it's null.
     
  7. Offline

    vasil7112

    So how can i give it the value of ConfigSetup?
     
  8. Offline

    metalhedd

    ConfigSetup is a class. you need to instantiate it and assign the results to 'configSetup'; that's basic java, not bukkit API. this isn't the place for it.
     
  9. Offline

    vasil7112

    That was what i had done with Static Methods, but alot of people recommended me to remove the Static Methods, as result, i had those problems :/
     
  10. Offline

    metalhedd

    you dont need static methods to do it. you just create a new ConfigSetup instance and assign it to the variable.
     
  11. Offline

    vasil7112

    So what you mean to say is to do the following
    public ConfigSetup configSetup = new ConfigSetup(this)
     
  12. Offline

    metalhedd

    well, there is no 'this' outside of any method, so taht's not going to work, but the general idea is correct. that's how you create a new instance.
     
  13. Offline

    vasil7112

    I changed this with 'plugin' and plugin is public Main plugin = this; (On Main)
    And on Listeners e.t.c
    public Main plugin;
    public Class(Main plugin){
    this.plugin = plugin;
    }
     
Thread Status:
Not open for further replies.

Share This Page