简体   繁体   中英

Exception in thread "main" java.lang.NoClassDefFoundError: org/bukkit/configuration/file/YamlConfiguration

I'm trying to make a Discord bot. For simplicity, I created a Minecraft project to use the Bukit (1.16.5) yml functions.

My friend did the same but he doesn't get the strange Error.

the error is in the line:

this.cfg = YamlConfiguration.loadConfiguration(giveawayStats);

Here is the whole class:

package de.pog.utils;

import org.bukkit.configuration.file.YamlConfiguration;

import java.io.File;
import java.io.IOException;
import java.util.Set;

public class GiveawayStats {

    public static File dataFolder;
    public static File giveawayStats;
    protected YamlConfiguration cfg;

public void loadFiles() {
    dataFolder = new File(System.getProperty("user.dir") + File.separator + "JonnyData");
    giveawayStats = new File(dataFolder.getAbsolutePath() + File.separator + "GiveawayStats.yml");

    if (!dataFolder.exists()) {
        dataFolder.mkdir();
    }

    if (!giveawayStats.exists()) {
        try {
            giveawayStats.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    this.cfg = YamlConfiguration.loadConfiguration(giveawayStats);
}

public void createGiveGiveAway() {
    if (giveawayIsRunning()) {
        this.cfg.set("winner", 0);
        this.cfg.set("prize", "");
        this.cfg.set("time", "");
        this.cfg.set("contributes", "");
        //cfg.save(giveawayStats);
    }
}

public boolean giveawayIsRunning() {
    Set<String> isEmpty = this.cfg.getKeys(false);

    return isEmpty.isEmpty();
  }
}

Maybe you know a solution:D

Java is an object-oriented programming language, so you need to define a class before specifying any methods with void or creating objects.

After fitting all that code within a class, you also need to specify a main method, so that the same class file becomes executable after being properly compiled.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM