NPE Error

Discussion in 'Plugin Development' started by EthanTek, Jul 4, 2012.

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

    EthanTek

    I'm getting a NPE on this:
    Code:
    this.db.insertQuery(query);
    Here is the relevant code:
    Code:
    public class CListener implements Listener {
        
        private static final Logger logger = Logger.getLogger("Minecraft");
        private sqlCore db;
    
        public CListener(Checkpoint plugin) {
            plugin.getServer().getPluginManager().registerEvents(this, plugin);
            
            this.db = new sqlCore(logger, "[Checkpoint] ", "Checkpoint", Checkpoint.pFolder.getPath());
        }
    ...
    Code:
                if(Checkpoint.doing.containsKey(event.getPlayer().getName())) {
                    if(Checkpoint.doing.get(event.getPlayer().getName()) == "checkpoint") {
                        String query = "INSERT INTO checkpoints (finish, x, y, z) VALUES (false, " + event.getClickedBlock().getX() + ", " +
                                event.getClickedBlock().getY() + ", " + event.getClickedBlock().getZ() + ");";
                        this.db.insertQuery(query);
                        event.getPlayer().sendMessage(ChatColor.GREEN + "[Checkpoint] Checkpoint Set!");
                        Checkpoint.doing.remove(event.getPlayer().getName());
                    }
    I am using alta189's SQLite library.
     
  2. Offline

    rutr

    You gave too little code.

    Code:
    this.db = new sqlCore
    give above:
    Code:
    logger.info("=====creating db object...");
    compile and run, and check if this message is send to console. if not, then db is null.
    I think the "public CListener(Checkpoint plugin)" is not called.
     
  3. Offline

    EthanTek

    thx. I fixed it using your help. I forgot to initialize() on my second class, which is necessary for some reason.
     
Thread Status:
Not open for further replies.

Share This Page