我怀疑问题不在于if
条件 - 而是在下面的陈述中。我将首先像这样重新格式化代码:
String description = getConfig().getString("core.commands." + cmd + ".description");
if (!description.isEmpty())
{
getCommand(cmd).setDescription(description);
}
else
{
getLogger().warning("NO description assigned to: " + cmd);
}
(我已经删除了该description = null;
声明,因为它几乎可以肯定是不必要的。)
通过这种更改,您将能够更多地了解引发异常的原因。你可以更进一步:
String description = getConfig().getString("core.commands." + cmd + ".description");
if (!description.isEmpty())
{
Command command = getCommand(cmd); // Or whatever type it is
command.setDescription(description);
}
else
{
getLogger().warning("NO description assigned to: " + cmd);
}
除此之外,当您现在在调试器中单步执行代码时(假设这甚至可行),您将能够判断是否command
为 null(我怀疑它是)。如果您不能使用调试器,您至少可以添加日志记录。
(其他人已经建议检查是否description
是null
,但听起来这不是问题,这就是为什么我建议问题可能出在if
语句的正文中。)