gpt4 book ai didi

java.lang.NullPointerException 错误请

转载 作者:行者123 更新时间:2023-12-02 08:46:12 24 4
gpt4 key购买 nike

我对编码真的很陌生,我一直在尝试制作这个我的世界插件。每次我启动它时都会出现此错误。 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com