java.lang.NullPointerException 错误请

标签 java nullpointerexception nullreferenceexception minecraft

我对编码真的很陌生,我一直在尝试制作这个我的世界插件。每次我启动它时都会出现此错误。 https://i.imgur.com/33lBHQr.png

这是“launcher.NitroLauncher.onEnable”类。

package launcher;

import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.plugin.java.JavaPlugin;

public class NitroLauncher extends JavaPlugin
{
    private NitroLaunch launch;
    private static NitroLauncher plugin;
    private ReflectiveOperationException e;

    public <Plugin> void onEnable() {
        NitroLauncher.plugin = this;
        try {
            this.launch = (NitroLaunch)Class.forName("me.R1J.nitro.NitroPlugin").asSubclass(NitroLaunch.class).newInstance();
            @SuppressWarnings("unchecked")
            Plugin plugin2 = (Plugin)this;
            new BukkitRunnable() {
                public void run() {
                    NitroLauncher.this.launch.launch(NitroLauncher.this);
                }
            }.runTask((org.bukkit.plugin.Plugin) plugin2);
        }
        catch (InstantiationException | IllegalAccessException | ClassNotFoundException ex2) {
            String str = e.getMessage(); ;
            ;
            e = new ReflectiveOperationException(str);;
            e.printStackTrace();
        }
    }

    public Object getValue(Object pojo) throws IllegalArgumentException
    {
      try {
        return _method.invoke(pojo, (Object[]) null);
      } catch (IllegalAccessException | InvocationTargetException e) {
        throw new IllegalArgumentException("Failed to getValue() with method "
            +getFullName()+": "+e.getMessage(), e);
      }
    }

    public void onDisable() {
        if (this.launch != null) {
            this.launch.shutdown();
        }
        this.launch = null;
        NitroLauncher.plugin = null;
    }

    public static NitroLauncher getPlugin() {
        return NitroLauncher.plugin;
    }
}

任何帮助将不胜感激!

谢谢

最佳答案

第 11 行:

private ReflectiveOperationException e;

您尝试在初始化它之前调用 getMessage() 。 第 26-28 行:

String str = e.getMessage(); ;
        ;
        e = new ReflectiveOperationException(str);;

由于变量“e”尚未设置任何内容,因此它默认为“null”值。

当您尝试执行诸如使用 null 变量调用函数之类的操作时,会导致 NullPointerException。

始终仔细检查您的代码是否存在此类愚蠢的错误,因为 99% 的情况下,这最终会破坏您的程序。 :)

关于java.lang.NullPointerException 错误请,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61070445/

相关文章:

C# 不会在开发人员机器上抛出 NullReferenceException

c# - Xamarin 自定义 UITableViewCell 抛出系统 NullReferenceException

java - 检查整个 firebase 数据库中是否存在字符串

java - Eclipse 不会推断匿名类的泛型吗?

java.lang.NullPointerException | java.lang.NullPointerException我的时钟不工作

java - 无法读取 jar 文件中的图像

c# - LINQ 查询中的 NullReferenceException

java - 调用 contains 时无法重写 Java 上的 Equals 方法

java - nextLine() 的问题;

java - 如何制作 Java Canvas 游戏循环