NumberFormatException Help

Discussion in 'Spigot Plugin Development' started by JordanOsterberg, May 12, 2015.

  1. Hello Spigot, I have encountered a NumberFormatException while using a String[].
        at$1.execute( ~[spigot.jar:git-Spigot-1649]
        at org.bukkit.plugin.RegisteredListener.callEvent( ~[spigot.jar:git-Spigot-1649]
        at org.bukkit.plugin.SimplePluginManager.fireEvent( [spigot.jar:git-Spigot-1649]
        at org.bukkit.plugin.SimplePluginManager.callEvent( [spigot.jar:git-Spigot-1649]
        at org.bukkit.craftbukkit.v1_7_R4.event.CraftEventFactory.callPlayerInteractEvent( [spigot.jar:git-Spigot-1649]
        at org.bukkit.craftbukkit.v1_7_R4.event.CraftEventFactory.callPlayerInteractEvent( [spigot.jar:git-Spigot-1649]
        at net.minecraft.server.v1_7_R4.PlayerConnection.a( [spigot.jar:git-Spigot-1649]
        at net.minecraft.server.v1_7_R4.PacketPlayInBlockPlace.a( [spigot.jar:git-Spigot-1649]
        at net.minecraft.server.v1_7_R4.PacketPlayInBlockPlace.handle( [spigot.jar:git-Spigot-1649]
        at net.minecraft.server.v1_7_R4.NetworkManager.a( [spigot.jar:git-Spigot-1649]
        at net.minecraft.server.v1_7_R4.ServerConnection.c( [spigot.jar:git-Spigot-1649]
        at net.minecraft.server.v1_7_R4.MinecraftServer.v( [spigot.jar:git-Spigot-1649]
        at net.minecraft.server.v1_7_R4.DedicatedServer.v( [spigot.jar:git-Spigot-1649]
        at net.minecraft.server.v1_7_R4.MinecraftServer.u( [spigot.jar:git-Spigot-1649]
        at [spigot.jar:git-Spigot-1649]
        at [spigot.jar:git-Spigot-1649]
    Caused by: java.lang.NumberFormatException: For input string: ""
        at java.lang.NumberFormatException.forInputString( ~[?:1.8.0_25]
        at java.lang.Integer.parseInt( ~[?:1.8.0_25]
        at java.lang.Integer.parseInt( ~[?:1.8.0_25]
        at com.thearchon.sgs.utils.Prizes.readPrizes( ~[?:?]
    Core plugin = Core.getCore();
        public ArrayList<Integer> readPrizes(Player player, String path)
            List<String> pathList = (List<String>) Core.instance.getConfig().getList(path);
            ArrayList<Integer> newList = new ArrayList<Integer>();
            String prizes = plugin.getSQL().getPrizes(player);
            String[] indexList = prizes.split("\\,");
            for(int x = 0; x<indexList.length; x++)
                int index = Integer.parseInt(indexList[x]);
                for(int y = 0; y<pathList.size(); y++)
            return newList;
    The error is here: int index = Integer.parseInt(indexList[x]);
    Thank you!
  2. gigosaurus


    Integer.parseInt(indexList[x]) causing NumberFormatException => indexList[x] is not a valid integer.

    You're expecting your prizes string to be a list of integers separated by commas, but somewhere it either has two commas next to each other, or the string starts / ends with a comma.
    Both of these would be invalid:

    Also there's no need to escape "," so change .split("\\,") to .split(",")
    #2 gigosaurus, May 12, 2015
    Last edited: May 12, 2015
  3. Right now, the prizes string is just "" because I don't have anything there. So are you saying I need something in the prizes string such as "5" for this to work?

    Edit: Worked, thank you.
  4. gigosaurus


    Oh yeah, forgot about empty strings. Yes, that would work.