Nullpointer Configuration

Discussion in 'Spigot Plugin Development' started by DaanSander, May 27, 2015.

  1. Hello, I was just messing around with my plugin when suddenly I found a nullpointerexception I debuged whole the code until I found what null was but i cant find why it is null I am assinging the FileConfiguration to getConfig in the onEnable() my config.yml exists i just cant find whats wrong can someone help me with this?

    code:
    Code (Text):
     public FileConfiguration config;

        public void onEnable() {
            config = this.getConfig();
             System.out.println(this.config.toString()); //<----- null
    sorry for bad english
     
  2. You don't need to declare config as a field. It's already declared in the JavaPlugin class. This code should work:
    Code (Text):
    public void onEnable() {
        FileConfiguration config = getConfig();
        System.out.println(config.toString());