java.lang.NullPointerException错误请请

问题描述 投票:0回答:1

我对编码真的很陌生,我一直在尝试制作这个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;
    }
}

任何帮助将不胜感激!

谢谢

java nullpointerexception nullreferenceexception minecraft
1个回答
0
投票

第11行:

private ReflectiveOperationException e;

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

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

由于变量'e'尚未设置为任何值,因此其默认值为'null'。

[当您尝试执行对变量为null的函数调用时,会导致该NullPointerException。

总是仔细检查代码,以免出现类似的愚蠢错误,因为在99%的时间内,这最终会破坏程序。 :)

© www.soinside.com 2019 - 2024. All rights reserved.