gpt4 book ai didi

java - MySQL Java Bukkit 插件 - 从数据库中选择

转载 作者:行者123 更新时间:2023-11-29 22:14:13 26 4
gpt4 key购买 nike

当我尝试从 MySQL 获取消息时,我的 Bukkit 插件出现问题。我有一个名为“ReportsLog”的表,其中存储“SenderName”和“Message”。

我认为Bukkit知识并不是解决这个问题所必须的,主要错误是:

     [01:44:19 ERROR]: null
org.bukkit.command.CommandException: Unhandled exception executing command 'areport' in plugin StaffTrainer v1.0

这是错误:

 [01:44:19 ERROR]: null
org.bukkit.command.CommandException: Unhandled exception executing command 'areport' in plugin StaffTrainer v1.0
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spi
got.jar:git-Spigot-f928e7a-e91aed8]
at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:14
1) ~[spigot.jar:git-Spigot-f928e7a-e91aed8]
at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServe
r.java:642) ~[spigot.jar:git-Spigot-f928e7a-e91aed8]
at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerCon
nection.java:1135) [spigot.jar:git-Spigot-f928e7a-e91aed8]
at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java
:970) [spigot.jar:git-Spigot-f928e7a-e91aed8]
at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java
:45) [spigot.jar:git-Spigot-f928e7a-e91aed8]
at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java
:1) [spigot.jar:git-Spigot-f928e7a-e91aed8]
at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:1
3) [spigot.jar:git-Spigot-f928e7a-e91aed8]
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [
?:1.8.0_45]
at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_45]
at net.minecraft.server.v1_8_R3.SystemUtils.a(SystemUtils.java:19) [spig
ot.jar:git-Spigot-f928e7a-e91aed8]
at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:7
18) [spigot.jar:git-Spigot-f928e7a-e91aed8]
at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:3
67) [spigot.jar:git-Spigot-f928e7a-e91aed8]
at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:6
57) [spigot.jar:git-Spigot-f928e7a-e91aed8]
at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java
:560) [spigot.jar:git-Spigot-f928e7a-e91aed8]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_45]
Caused by: java.lang.NullPointerException
at code.katzuno.StaffTrainer.onCommand(StaffTrainer.java:80) ~[?:?]
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spi
got.jar:git-Spigot-f928e7a-e91aed8]
... 15 more

这是第 80 行的代码(有错误的代码):

            String ReportSender = args[0];
String mesaj = mess.getMessage(ReportSender);

错误很可能出在函数 getMessage 中。这是函数 getMessage()

的代码
   public String getMessage(String PlayerName) {
String mesaj = " ";
if (playerExists(PlayerName)) {
try {
ResultSet rs = StaffTrainer.mysql.query("SELECT * FROM ReportsLog WHERE SenderName= '" + PlayerName + "'");
if ( (!rs.next()) || (String.valueOf(rs.getString("Message")) == null) );
mesaj = rs.getString("Message");
} catch (SQLException e) {
e.printStackTrace();
}
} else {
createPlayer(PlayerName);
getMessage(PlayerName);
}
return mesaj;
}

最佳答案

args 变量为空。它表示空指针异常来自该行,并且您尝试访问值的唯一位置是来自该数组。您需要提前进行检查,如下所示:

if (args != null) {
...
}

防止异常发生。

关于java - MySQL Java Bukkit 插件 - 从数据库中选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31351554/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com