[英]When i load my minecraft i get the error java.lang.NullPointerExeption how can i fix this?
Hello so i am making a minecraft plugin here is the code你好所以我正在制作一个我的世界插件这是代码
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import me.EpicGamese.CustomEssentials.Main;
import me.EpicGamese.CustomEssentials.utils.Utils;
public class FlyCommand implements CommandExecutor {
private Main plugin;
public FlyCommand(Main plguin) {
this.plugin = plugin;
plugin.getCommand("fly").setExecutor(this);
}
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage(Utils.chat(plugin.getConfig().getString("Hello")));
return true;
}
Player p = (Player) sender;
if (p.hasPermission("SubgGame.fly")) {
if (p.isFlying()) {
p.setAllowFlight(false);
p.setFlying(false);
p.sendMessage(Utils.chat(plugin.getConfig().getString("Hello")));
return true;
} else {
p.setAllowFlight(true);
p.setFlying(true);
p.sendMessage(Utils.chat(plugin.getConfig().getString("Hello")));
}
} else {
p.sendMessage(Utils.chat("Hello"));
}
return false;
}
}
and when i try and load it into my server i get the error java.lang.NullPointerExeption can some one help and i am coding the plugin for 1.8.8 minecraft当我尝试将其加载到我的服务器中时,我收到错误 java.lang.NullPointerExeption 可以提供一些帮助,我正在为 1.8.8 minecraft 编写插件
Line 18 is your NPE.第 18 行是你的 NPE。 Here's the problem:这是问题所在:
private Main plugin;
public FlyCommand(Main plguin) {
this.plugin = plugin;
plugin.getCommand("fly").setExecutor(this);
}
You defined a Main plugin
which will default to NULL.您定义了一个默认为 NULL 的Main plugin
。 In FlyCommand
you get passed a variable you called plguin
and then you assign this.plugin
to plugin
(assigning it to itself, not the value passed into the func b/c you misspelled that).在FlyCommand
,您传递了一个名为plguin
的变量,然后将this.plugin
分配给plugin
(将其分配给它自己,而不是传递给您拼写错误的 func b/c 的值)。
You probably meant to:您可能打算:
this.plugin = plguin;
Notice the gui vs ugi.注意 gui 与 ugi。 To void this and make the code more readable I would call that argument passed into the function something more different, maybe just p
.为了使这一点无效并使代码更具可读性,我将传递给 function 的参数称为更不同的东西,也许只是p
。
private Main plugin;
public FlyCommand(Main p) {
this.plugin = p;
plugin.getCommand("fly").setExecutor(this);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.