A very strange null pointer exception

Discussion in 'Plugin Development' started by SaxSalute, Jul 1, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    SaxSalute

    I just started coding plugins today and I am working on a home management plugin to allow players to buy and sell land on their own. I just got to a testing point and I'm running into a very strange null pointer exception.

    Code:
    package com.github.SaxSalute.HomeManager;
    
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.Location;
    
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.Map;
    
    public class HomeManager extends JavaPlugin
    {
        //The command executor
        private HomeManagerCommandExecutor myExecutor;
        //A map of Players and the two locations that they have selected
        protected Map<Player, Location[]> selectedLocations;
        //An arraylist of all regions
        protected ArrayList<Region> regions;
        
        public void onEnable()
        {
            //Creates the command executor and register the commands
            myExecutor = new HomeManagerCommandExecutor(this);
            if (myExecutor != null)
                getCommand("createhome").setExecutor(myExecutor);
            
            //Registers the wand click listener
            getServer().getPluginManager().registerEvents(new WandClickListener(this), this);
            
            //Creates selectedLocations
            selectedLocations = new HashMap<Player, Location[]>();
            
            //Create regions
            regions = new ArrayList<Region>();
        }
        
        public void onDisable()
        {
            getLogger().info("Home Manager has been disabled");
        }
    }
    
    
    The error is on line 25, the line where I assign myExecutor as the command executor for the createhome command. It's a null pointer exception, but I can't imagine for the life of me what is null! I tried just calling 'getCommand("createhome");' and that ran error free. It's only when I add the rest of the line that I get the null pointer exception, which I assume to be on myExecutor. Please help!
     
  2. Offline

    Pandemoneus

    You always get NPEs on getCommand(...).someMethod() when you didn't specify the command in your plugin.yml.
     
    ferrybig likes this.
  3. Offline

    SaxSalute

    I just went to my plugin.yml and realized that I didn't put an 's' on commands:. I never would have caught that! Thanks!
     
Thread Status:
Not open for further replies.

Share This Page