Solved NullPointerException with Config

Discussion in 'Plugin Development' started by MasterDoctor, Nov 1, 2015.

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

    MasterDoctor

    I am setting up a config from another class, I have got my constructors set up (my main class is Main.java)
    Here is my constructor:
    Code:
        Main plugin;
    
        public ListenerClass(Main instance) {
            plugin = instance;
            plugin.getServer().getPluginManager().registerEvents(this, plugin);
        }
    When I try and use the config:
    Code:
    String prefix3 = plugin.getConfig().getString("chat.prefix");
    I get a NullPointerException...
    HELP!!!
     
  2. Offline

    NullChips

    More info is needed. Do you have chat.prefix in your config? Is your config there?
     
  3. Offline

    Astrophylite

    @MasterDoctor
    Is there an error showing up in console? If so, please post it here.
    Has your config been set-up correctly? (e.g: getConfig().options().copyDefaults(true); saveConfig(); )
    More information is needed as @NullChips said.
     
  4. Offline

    87pen

    You're trying to access a variable in your config that does not exist. Set the config area using the getConfig().set method and save your config before trying to access it. Most likely you spelt the variable wrong in your set method, you didn't set a a chat.prefix or you are not saving your config using saveConfig() after setting it. I would also regularly use null checks.
     
    Last edited: Nov 1, 2015
  5. Offline

    MasterDoctor

    I found the problem, I registered my listener before I saved the config :p
     
Thread Status:
Not open for further replies.

Share This Page