Solved NullPointerException on trying to make a file

Discussion in 'Plugin Development' started by AlfieJay, May 24, 2020.

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


    So I've been struggling to make a file for my plugin to save data, I keep getting the NullPointerException (on the line marked with ##)

    Separate class method:
        static void load() {
            File file = new File(plugin.getDataFolder()+File.separator+"data.yml"); ##
            //FileConfiguration config = YamlConfiguration.loadConfiguration(file);
            if (!file.exists()) {
                try {
                } catch (IOException e) {
    Main class onEnable:
        public void onEnable() {
            FILEMANAGER.load(); ##
            PluginManager pm = getServer().getPluginManager();
            LISTENER listener = new LISTENER(this);
            pm.registerEvents(listener, this);
            plugin = this;
    Please help if you know how I can fix this. Thanks a bunch :D
  2. Offline

    timtower Moderator Moderator

    @AlfieJay plugin is null.
    Solution: don't use static config handlers. Make an instance that takes the main class as parameter in the constructor.
  3. Offline


    Thanks so much for the help, it works fine now :D
Thread Status:
Not open for further replies.

Share This Page