Bug I cant seem to squash.

Discussion in 'Plugin Development' started by multi_coder, Mar 21, 2011.

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

    multi_coder

    Here is the code for a plugin I am worknig on. I have spent several hours on it to no avail at this point I figure I must just be making a stupid mistake somewhere. The code all complies fine but when it runs I get the error below. Any ideals? Sorry the code is 'dirty' I usually clean and pretty the code up once I get it working all the way. The data file this uses is attached.
    Code:
    22:45:35 [SEVERE] java.lang.NullPointerException
    22:45:35 [SEVERE]     at com.bukkit.multi.item.SmartItem.onCommand(SmartItem.java:78)
    22:45:35 [SEVERE]     at org.bukkit.command.PluginCommand.execute(PluginCommand.java:35)
    22:45:35 [SEVERE]     at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:80)
    22:45:35 [SEVERE]     at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:183)
    22:45:35 [SEVERE]     at net.minecraft.server.NetServerHandler.c(NetServerHandler.java:645)
    22:45:35 [SEVERE]     at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:608)
    22:45:35 [SEVERE]     at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:602)
    22:45:35 [SEVERE]     at net.minecraft.server.Packet3Chat.a(SourceFile:24)
    22:45:35 [SEVERE]     at net.minecraft.server.NetworkManager.a(SourceFile:230)
    22:45:35 [SEVERE]     at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:76)
    22:45:35 [SEVERE]     at net.minecraft.server.NetworkListenThread.a(SourceFile:100)
    22:45:35 [SEVERE]     at net.minecraft.server.MinecraftServer.h(MinecraftServer.java:357)
    22:45:35 [SEVERE]     at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:272)
    22:45:35 [SEVERE]     at net.minecraft.server.ThreadServerApplication.run(SourceFile:366)
    
    Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package com.bukkit.multi.item;
    
    import java.sql.*;
    import java.io.File;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.HashMap;
    import java.util.logging.Logger;
    import org.bukkit.block.Block;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Event;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.Material;
    import java.io.IOException;
    /**
     *
     * @author multicoder
     */
    public class SmartItem extends JavaPlugin{
            public static final Logger log = Logger.getLogger("Minecraft");
            public void onEnable() {
            log.info("[SmartItem Enabled]");
        }
        public void onDisable() {log.info("[SmartItem Disbled]");}
            public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) {
        String[] split = args;
        String commandName = command.getName().toLowerCase();
            if (sender instanceof Player) {
                Player player = (Player) sender;
                log.info("["+player.getName()+":/"+commandName+" "+split[0]+"]");
                if ((commandName.equals("item")) || (commandName.equals("i"))){
                    int id=0;
                    try{
                    id=Integer.parseInt(split[0]);
                         if ((id==51) || (id==52) || (id==87) ||
                                (id==7) || (id==8) || (id==9) || (id==52) || (id==10)||
                                (id==11)|| (id==7)|| (id==90)|| (id==91)||
                                (id==92)|| (id==93)|| (id==94)){
                        player.chat("<Attemped spawn a dangerous block! ID:"+id+">");
                        }
                        else{
                        player.getInventory().addItem(new ItemStack(Material.getMaterial(id),64));
                        }
                    //ItemStack stack = new ItemStack(id, count, damage);
                    }
                    catch (Exception e){
                        //e.//
                        try{
                        try{
                        Class.forName("org.sqlite.JDBC");
                            }
                        catch(ClassNotFoundException Ej){
                            log.info(Ej.getLocalizedMessage());
                        }
                        log.info("SQL is working!");
                        Connection conn = DriverManager.getConnection("jdbc:sqlite:Mitems.db");
                        log.info("Connected to database!");
                        Statement stat = conn.createStatement();
                        ResultSet rs = stat.executeQuery("select * from items;");
                        log.info("Statement ready!");
                        int tempI;
                        log.info("Var loaded!");
                        try{
                        while (rs.next()) {
                            String name="",Sid="",damage="";
                            name    = rs.getString("name");
                            Sid     = rs.getString("id");
                            damage  = rs.getString("damage");
                            tempI   = Integer.getInteger(damage);
                            log.info(name+Sid+id+damage);
                        if (name.equalsIgnoreCase(split[0]));
                            {
                            log.info("Item Matched");
                            //make the item
                            //ItemStack stack = new ItemStack(id, 64, tempI);
                            //player.getInventory().addItem(stack);
                            player.getInventory().addItem(new ItemStack(Material.getMaterial(Sid),64));
                            }
    
                        }}
                        catch(Exception R)
                        {
                            R.printStackTrace();
                        }
                        rs.close();
                        conn.close();}
                        catch(Exception ex){
                            log.info(ex.getLocalizedMessage());
                        }
                        }
                    }
            }
        return true;
        }
    }
    
     

    Attached Files:

  2. Offline

    Drakia

    You're using the wrong function for getting an integer. Integer.getInteger() is used for "Determines the integer value of the system property with the specified name. "
    What you're looking for is either use rs.getInt("damage") or Integer.valueOf(damage)
     
  3. Offline

    multi_coder

    Thanks for the help. I figured it had to be something small.
     
Thread Status:
Not open for further replies.

Share This Page