NPE on config read

Discussion in 'Plugin Development' started by chrisman0091, Jan 6, 2014.

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


    So I'm using the default config API in Bukkit, but am having troubles grabbing values from the config.

    Main class:
    1. public class BukkitMC extends JavaPlugin {
    3. public static BukkitMC inst;
    4. public void onEnable(){
    5. Bukkit.getServer().getPluginManager().registerEvents(new Listeners(), this);
    6. getCommand("vote").setExecutor(new Commands());
    7. getCommand("website").setExecutor(new Commands());
    8. getCommand("clearchat").setExecutor(new Commands());
    9. getCommand("welcomebook").setExecutor(new Commands());
    10. getCommand("rules").setExecutor(new Commands());
    12. this.saveDefaultConfig();
    13. inst = this;
    14. }
    16. public void onDisable(){}
    17. }

    My website command(the one in question):
    1. if (label.equalsIgnoreCase("website")){
    2. sender.sendMessage(Utils.colorize(BukkitMC.inst.getConfig().getString("website-msg")));
    3. }

    You can ignore the Utils.colorize part, that just translates the color codes. The line giving the NPE is the sender.sendMessage line.

    website-msg: '&eFind our website at &7'

    It is literally that one line. I have tested to make sure sender is not null just in case. What am I doing wrong?

    Still really need help on this.

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


    Couldn't see anything wrong with it yet either. Could you post the colorize-method?
  3. Offline


    Sure. I use it in other plugins/code too and it works fine, and its very simple.
    1. public static String colorize(String s) {
    2. return ChatColor.translateAlternateColorCodes('&', s);
    3. }
  4. Does the npe still appear when you use a default value when getting the string from the config?
  5. Offline



    So I did some testing, and after renaming the plugin's folder, its not even generating the folder back. So its not even creating a config(though I had one before), and I do have a this.saveDefaultConfig() in the onEnable as you can see.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 6, 2016
  6. Well, if you don't have a default config, it won't be able to save it, or do you have one?
    However, that shouldn't really be the issue, especially when it still gives you an npe while providing a default value...
  7. Offline


    What exactly do/did you mean by default value? I might have misunderstood you, I just tried it without my colorize method :p And yes I do have a default config for it to save.
  8. Offline


Thread Status:
Not open for further replies.

Share This Page