简体   繁体   English

当我加载我的我的世界时,我收到错误 java.lang.NullPointerExeption 我该如何解决这个问题?

[英]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.

相关问题 为什么我会得到nullpointerexeption? - why do i get nullpointerexeption? Minecraft Plugin 如何在这里修复我的武器系统? - Minecraft Plugin how can I fix my Weapon System here? 我正在尝试创建我的世界服务器,但每次启动时都会出现错误,我该如何解决? - I am trying to create a minecraft server but every time I start it I get an error, how can I fix it? (Java) 如何在我的插件中使用 minecraft 原始命令? - (Java) How can I use minecraft original commands in my plugin? 尝试在我的世界启动器 VoidsWrath 中运行 mod,我收到错误 java.lang.NoClassDefFoundError: javax/servlet/ServletContextListener - Trying to run mods in minecraft launcher VoidsWrath and i get the error java.lang.NoClassDefFoundError: javax/servlet/ServletContextListener 运行我得到的 Minecraft 服务器和 java arrayOutofBounds 我该如何解决这个问题? - Running a Minecraft server I get and java arrayOutofBounds how do I fix this? 在我的代码中输入一个需要 int 的字符串,我得到一个 java 错误我该如何解决这个问题? - Inputting a string into my code that an int is required and I get a java error how can I fix this? 如何修复在包中移动我的java文件后出现的错误“java.lang.NoClassDefFoundError”? - How can I fix the error “java.lang.NoClassDefFoundError” that has occured after moving my java files in packages? 如何在我的 1.19.2 minecraft mod 中修复 common_setup 期间的错误” - How do i fix an error during common_setup in my 1.19.2 minecraft mod" 如何修复java.lang.NullPointerException(android)? - How do I fix my java.lang.NullPointerException (android)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM