Solved NullPointerException with Config

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

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


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


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


    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


    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


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

Share This Page