NullPointerException

Discussion in 'Plugin Development' started by TechGuard, Jan 17, 2011.

Thread Status:
Not open for further replies.
  1. Sorry, but I don't know how to get it to work.
    Error:
    Code:
    SEVERE: Could not  pass event PLAYER_COMMAND to Skillz
    java.lang.NullPointerException
    Script
    Code:
    public void onPlayerCommand(PlayerChatEvent event) {
             String[] cmd = event.getMessage().split(" ");
    
             if (cmd[0].equalsIgnoreCase("/command")) {;
                 event.setCancelled(true);
             }
        }
     
  2. Offline

    Plague

    Do you register the event, using something similar?
    Code:
    PluginManager pm = getServer().getPluginManager();
    pm.registerEvent(Event.Type.PLAYER_COMMAND, playerListener, Priority.Normal, this);
    Although I do not really see why this would raise this exception...
     
  3. Yes I did that.
     
  4. Offline

    apexearth

    Code:
    public void onPlayerCommand(PlayerChatEvent event) {
             String[] cmd = event.getMessage().split(" ");
    
             if (cmd[0].equalsIgnoreCase("/command")) {;   <---Why is there a ; there?
                 event.setCancelled(true);
             }
        }
    Other than that oddity, all I can really offer you in terms of advice is for you to go overboard with separating everything out to pinpoint the null object. Which as far as I can see is either getMessage() or the event variable.

    Code:
    public void onPlayerCommand(PlayerChatEvent event) {
           String s = event.getMessage();
           if(s!=null){
             String[] cmd = s.split(" ");
    
             if (cmd.length>0 && cmd[0].equalsIgnoreCase("/command")) {
                 event.setCancelled(true);
             }
          }
        }
     
  5. Oh, pretty dumb I typed the ; there, but it isn't in my script :p
     
Thread Status:
Not open for further replies.

Share This Page