请检查java.lang.NullPointerException错误
我对编码非常陌生,我一直在尝试制作这个minecraft插件。每次启动它,我都会遇到这个错误 这是launcher.NitroLauncher.oneable类请检查java.lang.NullPointerException错误,java,nullpointerexception,nullreferenceexception,minecraft,Java,Nullpointerexception,Nullreferenceexception,Minecraft,我对编码非常陌生,我一直在尝试制作这个minecraft插件。每次启动它,我都会遇到这个错误 这是launcher.NitroLauncher.oneable类 package launcher; import org.bukkit.plugin.Plugin; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.plugin.java.JavaPlugin; public class NitroLauncher ext
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%的情况下,这些错误最终会破坏你的程序 错误显示在第26行,但这只是catch子句中的消息,这意味着实际错误发生在第15行和第24行之间的try中。检查您在那里使用的任何元素是否返回null,乍一看,主要的可疑元素可能是Class.forNameme.R1J.nitro.nitroplugin您在第26行周围有一堆不需要的分号。尝试删除它们并检查发生了什么。您可以在这里添加e.getMessage,它们正在查找错误变量,该变量定义为ex2