Class不存在和存在

Class does not exist and exists

我收到一个 NoClassDefFoundError 异常,我不知道为什么,因为我的 class 是导入的,编译器中没有错误,但是当我 运行 插件时,错误是。我什至检查了 .class 文件是否存在于 .jar 文件中并且它存在所以我不知道这里的问题是我得到的异常:

[22:45:24] [Server thread/ERROR]: null
org.bukkit.command.CommandException: Unhandled exception executing command 'sb' in plugin YTScoreboard v2.6.3
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:47) ~[1.16.jar:3096a-Spigot-9fb885e-af1a232]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:149) ~[1.16.jar:3096a-Spigot-9fb885e-af1a232]
        at org.bukkit.craftbukkit.v1_16_R3.CraftServer.dispatchCommand(CraftServer.java:761) ~[1.16.jar:3096a-Spigot-9fb885e-af1a232]
        at net.minecraft.server.v1_16_R3.PlayerConnection.handleCommand(PlayerConnection.java:1936) ~[1.16.jar:3096a-Spigot-9fb885e-af1a232]
        at net.minecraft.server.v1_16_R3.PlayerConnection.c(PlayerConnection.java:1779) ~[1.16.jar:3096a-Spigot-9fb885e-af1a232]
        at net.minecraft.server.v1_16_R3.PlayerConnection.a(PlayerConnection.java:1732) ~[1.16.jar:3096a-Spigot-9fb885e-af1a232]
        at net.minecraft.server.v1_16_R3.PacketPlayInChat.a(PacketPlayInChat.java:49) ~[1.16.jar:3096a-Spigot-9fb885e-af1a232]
        at net.minecraft.server.v1_16_R3.PacketPlayInChat.a(PacketPlayInChat.java:1) ~[1.16.jar:3096a-Spigot-9fb885e-af1a232]
        at net.minecraft.server.v1_16_R3.PlayerConnectionUtils.lambda[=11=](PlayerConnectionUtils.java:28) ~[1.16.jar:3096a-Spigot-9fb885e-af1a232]
        at net.minecraft.server.v1_16_R3.TickTask.run(SourceFile:18) ~[1.16.jar:3096a-Spigot-9fb885e-af1a232]
        at net.minecraft.server.v1_16_R3.IAsyncTaskHandler.executeTask(SourceFile:144) ~[1.16.jar:3096a-Spigot-9fb885e-af1a232]
        at net.minecraft.server.v1_16_R3.IAsyncTaskHandlerReentrant.executeTask(SourceFile:23) ~[1.16.jar:3096a-Spigot-9fb885e-af1a232]
        at net.minecraft.server.v1_16_R3.IAsyncTaskHandler.executeNext(SourceFile:118) ~[1.16.jar:3096a-Spigot-9fb885e-af1a232]
        at net.minecraft.server.v1_16_R3.MinecraftServer.bb(MinecraftServer.java:1061) ~[1.16.jar:3096a-Spigot-9fb885e-af1a232]
        at net.minecraft.server.v1_16_R3.MinecraftServer.executeNext(MinecraftServer.java:1054) ~[1.16.jar:3096a-Spigot-9fb885e-af1a232]
        at net.minecraft.server.v1_16_R3.IAsyncTaskHandler.executeAll(SourceFile:103) ~[1.16.jar:3096a-Spigot-9fb885e-af1a232]
        at net.minecraft.server.v1_16_R3.MinecraftServer.sleepForTick(MinecraftServer.java:1037) ~[1.16.jar:3096a-Spigot-9fb885e-af1a232]
        at net.minecraft.server.v1_16_R3.MinecraftServer.w(MinecraftServer.java:970) ~[1.16.jar:3096a-Spigot-9fb885e-af1a232]
        at net.minecraft.server.v1_16_R3.MinecraftServer.lambda[=11=](MinecraftServer.java:273) ~[1.16.jar:3096a-Spigot-9fb885e-af1a232]
        at java.lang.Thread.run(Thread.java:831) [?:?]
Caused by: java.lang.NoClassDefFoundError: Could not initialize class pl.Werokowy.ytscoreboard.ScoreboadAPI
        at pl.Werokowy.ytscoreboard.SBCmd.onCommand(SBCmd.java:57) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[1.16.jar:3096a-Spigot-9fb885e-af1a232]
        ... 19 more

代码非常简单,所以我不想展示它:ScoreboardAPI.updateScoreboard()

如果 classes 在编译期间没有产生问题并且 jar 文件是从中构建的,我假设两个 classes 是同一个 jar 的一部分,因此 class路径不是问题。

查看 NoClassDefFoundError 中的文本:无法初始化 class pl.Werokowy.ytscoreboard.ScoreboadAPI

这不是“ClassNotFoundException”,它指向构建 class 或实例时出现的问题。也许不是构造函数抛出异常,但也可能是除了构造函数之外甚至 class 级别需要 运行 的代码。

检查您的变量定义(以及它们的初始化方式),并检查静态初始化程序。