NullPointerException无论如何都保持在同一行

时间:2015-03-09 02:58:18

标签: java eclipse bukkit

我试图对这个Minecraft插件进行编码,但是我继续在CompMeme类(第16行)的onEnable()上获得NullPointerException,奇怪的是在同一行,即使我放了一个System.out.print()如果NullPointerException不存在,那么插件只是在没有任何消息的情况下加载。如何修复此NullPointerException?

[21:51:15] [Server thread/ERROR]: Error occurred while enabling CompMeme v0.1.5-SNAPSHOT (Is it up to date?)
java.lang.NullPointerException
    at escaperestart.sircomputer.compmeme.CompMeme.onEnable(CompMeme.java:16) ~[?:?]
    at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
    at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:335) [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
    at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
    at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugin(CraftServer.java:356) [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
    at org.bukkit.craftbukkit.v1_8_R1.CraftServer.enablePlugins(CraftServer.java:316) [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
    at net.minecraft.server.v1_8_R1.MinecraftServer.q(MinecraftServer.java:402) [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
    at net.minecraft.server.v1_8_R1.MinecraftServer.k(MinecraftServer.java:370) [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
    at net.minecraft.server.v1_8_R1.MinecraftServer.a(MinecraftServer.java:325) [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
    at net.minecraft.server.v1_8_R1.DedicatedServer.init(DedicatedServer.java:211) [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
    at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:505) [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3]
    at java.lang.Thread.run(Thread.java:744) [?:1.7.0_51

我不确定我做错了什么,这是我的CompMeme课程:

public final class CompMeme extends JavaPlugin {

    public static CompMeme plugin;
    public String version = "0.1.6-SNAPSHOT";

    public void onEnable() {
        getConfig().options().copyDefaults(true);
        saveConfig();

        getCommand("rofl").setExecutor(Executor.rofl);
        getCommand("facepalm").setExecutor(Executor.facepalm);
        getCommand("lol").setExecutor(Executor.lol);
        getCommand("iliketrains").setExecutor(Executor.iliketrains);
        getCommand("blamenill").setExecutor(Executor.blamenill);
        getCommand("odns").setExecutor(Executor.odns);
        getCommand("ragequit").setExecutor(Executor.ragequit);
        getCommand("rage").setExecutor(Executor.rage);
        getCommand("compmeme").setExecutor(Executor.compmemecmd);
    }

    public void onDisable() {
        saveConfig();
    }
}

这是我的Executor课程:

public class Executor {
    public static CompMeme compmeme = CompMeme.plugin;

    public static BasicCommand rofl = new BasicCommand(compmeme, "rofl", ChatColor.DARK_GREEN, "[Rofl]");
    public static BasicCommand facepalm = new BasicCommand(compmeme, "facepalm", ChatColor.AQUA, "[Facepalm]");
    public static BasicCommand lol = new BasicCommand(compmeme, "lol", ChatColor.DARK_GREEN, "[Lol]");
    public static BasicCommand iliketrains = new BasicCommand(compmeme, "iliketrains", ChatColor.DARK_PURPLE, "[Trains!]");
    public static BasicCommand blamenill = new BasicCommand(compmeme, "blamenill", ChatColor.DARK_RED, "[Blame Nill]");
    public static InputCommand odns = new InputCommand(compmeme, "odns", ChatColor.GOLD, "[ODNS]");
    public static Rage rage = new Rage(compmeme);
    public static Ragequit ragequit = new Ragequit(compmeme);
    public static CompMemeCmd compmemecmd = new CompMemeCmd(compmeme);
}

这里是plugin.yml

name: CompMeme
main: escaperestart.sircomputer.compmeme.CompMeme
version: 0.1.5-SNAPSHOT
description: Meme commands for EscapeRestart
author: SirComputer

commands:
  rofl:
   description: Makes you roll on the floor laughing.
   usage: /rofl
   permission: compmeme.rofl

  facepalm:
   description: Makes you facepalm.
   usage: /facepalm
   permission: compmeme.facepalm

   lol:
    description: Makes you laugh out loud.
    usage: /lol
    permission: compmeme.lol

   iliketrains:
    description: Show your support for trains.
    usage: /iliketrains
    permission: compmeme.lol
    aliases: trains

   blamenill:
    description: Makes you blame Nill.
    usage: /blamenill
    permission: compmeme.blamenill

   odns:
    description: One does not simply...
    usage: /odns
    permission: compmeme.odns

   ragequit:
    description: Makes you ragequit.
    usage: /ragequit
    permission: compmeme.ragequit

   rage:
    description: Activate or deactivate rage mode.
    usage: /rage [activate/deactivate]
    permission: compmeme.rage
    aliases: ragemode

   compmeme:
    description: CompMeme information command.
    usage: /compmeme <info/enable/disable>
    permission: compmeme.compmeme
    aliases: ragemode

permissions:
  compmeme.*:
    default: op
    description: Ops get ALL the commands!
    children:
     compmeme.rofl: true
     compmeme.facepalm: true
     compmeme.lol: true
     compmeme.iliketrains: true
     compmeme.blamenill: true
     compmeme.odns: true
     compmeme.ragequit: true
     compmeme.rage: true
     compmeme.compmeme: true
     compmeme.enable: true
     compmeme.disable: true

我不确定是否有其他人在Minecraft插件中发生过这种情况 - 看起来它在其他事情上发生过一次或两次。

2 个答案:

答案 0 :(得分:1)

当您尝试在NullPointerException的对象上运行方法时,会抛出null

你的例外说:

at escaperestart.sircomputer.compmeme.CompMeme.onEnable(CompMeme.java:16) ~[?:?]

意味着在NullPointerException的第16行有一个CompMeme.java,这就是这一行:

getCommand("rofl").setExecutor(Executor.rofl);

问题实际上似乎不是getCommand("rofl"),而是你的plugin.yml,它没有正确缩进。这是我将其粘贴到YAML to JSON parser

时得到的结果
{
  "commands": {
    "facepalm": {
      "blamenill": {
        "usage": "/blamenill", 
        "description": "Makes you blame Nill.", 
        "permission": "compmeme.blamenill"
      }, 
      "description": "Makes you facepalm.", 
      "ragequit": {
        "usage": "/ragequit", 
        "description": "Makes you ragequit.", 
        "permission": "compmeme.ragequit"
      }, 
      "permission": "compmeme.facepalm", 
      "odns": {
        "usage": "/odns", 
        "description": "One does not simply...", 
        "permission": "compmeme.odns"
      }, 
      "rage": {
        "usage": "/rage [activate/deactivate]", 
        "permission": "compmeme.rage", 
        "description": "Activate or deactivate rage mode.", 
        "aliases": "ragemode"
      }, 
      "lol": {
        "usage": "/lol", 
        "description": "Makes you laugh out loud.", 
        "permission": "compmeme.lol"
      }, 
      "iliketrains": {
        "usage": "/iliketrains", 
        "permission": "compmeme.lol", 
        "description": "Show your support for trains.", 
        "aliases": "trains"
      }, 
      "usage": "/facepalm", 
      "compmeme": {
        "usage": "/compmeme <info/enable/disable>", 
        "permission": "compmeme.compmeme", 
        "description": "CompMeme information command.", 
        "aliases": "ragemode"
      }
    }, 
    "rofl": {
      "usage": "/rofl", 
      "description": "Makes you roll on the floor laughing.", 
      "permission": "compmeme.rofl"
    }
  }, 
  "permissions": {
    "compmeme.*": {
      "default": "op", 
      "description": "Ops get ALL the commands!", 
      "children": {
        "compmeme.odns": true, 
        "compmeme.facepalm": true, 
        "compmeme.iliketrains": true, 
        "compmeme.blamenill": true, 
        "compmeme.rofl": true, 
        "compmeme.ragequit": true, 
        "compmeme.rage": true, 
        "compmeme.compmeme": true, 
        "compmeme.disable": true, 
        "compmeme.lol": true, 
        "compmeme.enable": true
      }
    }
  }
}

如您所见,plugin.yml中从lolcompmeme的命令缩进了1个空格。要解决此问题,您应该将plugin.yml更改为:

commands:
  rofl:
   description: Makes you roll on the floor laughing.
   usage: /rofl
   permission: compmeme.rofl

  facepalm:
   description: Makes you facepalm.
   usage: /facepalm
   permission: compmeme.facepalm

  lol:
   description: Makes you laugh out loud.
   usage: /lol
   permission: compmeme.lol

  iliketrains:
   description: Show your support for trains.
   usage: /iliketrains
   permission: compmeme.lol
   aliases: trains

  blamenill:
   description: Makes you blame Nill.
   usage: /blamenill
   permission: compmeme.blamenill

  odns:
   description: One does not simply...
   usage: /odns
   permission: compmeme.odns

  ragequit:
   description: Makes you ragequit.
   usage: /ragequit
   permission: compmeme.ragequit

  rage:
   description: Activate or deactivate rage mode.
   usage: /rage [activate/deactivate]
   permission: compmeme.rage
   aliases: ragemode

  compmeme:
   description: CompMeme information command.
   usage: /compmeme <info/enable/disable>
   permission: compmeme.compmeme
   aliases: ragemode

permissions:
  compmeme.*:
    default: op
    description: Ops get ALL the commands!
    children:
     compmeme.rofl: true
     compmeme.facepalm: true
     compmeme.lol: true
     compmeme.iliketrains: true
     compmeme.blamenill: true
     compmeme.odns: true
     compmeme.ragequit: true
     compmeme.rage: true
     compmeme.compmeme: true
     compmeme.enable: true

lolcompmeme的命令开头删除一个空格,同时删除usagepermissiondescription的一个空格,以及aliases中的plugin.yml部分命令。

您应始终将plugin.yml粘贴到YAML解析器中,例如http://yaml-online-parser.appspot.com/,以确保没有错误。

答案 1 :(得分:0)

这一行

at escaperestart.sircomputer.compmeme.CompMeme.onEnable(CompMeme.java:16) ~[?:?]

表示。

1。)班级escaperestart.sircomputer.compmeme.CompMeme

Method `onEnable()`,

Line 16

2。)来到java文件的第16行,

getCommand("lol").setExecutor(Executor.lol);

可能性是 - getCommand("lol")返回null。

请在这里调试,不知怎的问题只在这里发生。