String to integer problem

Discussion in 'Plugin Development' started by Moon_werewolf, Sep 26, 2011.

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

    Moon_werewolf

    I have a very odd string to Integer problem

    Here is what i get in the console
    here is my strToInt Script
    Code:
    public static int strToInt(String txt, int ifNot)
        {
            if(txt == null)
            {
                return ifNot;
            }
    
            try
            {
                return Integer.parseInt(txt,ifNot);
            }catch(Exception e){
                System.out.println("Error: strToInt("+txt+","+ifNot+")");
                return ifNot;
            }
        }
    and here is the code that trying to run the strToInt
    Code:
    System.out.println(unpacked.get(0));
                String[] data = unpacked.get(0).split(sep);
                int x = tr.strToInt(data[0], 0);
                int y = tr.strToInt(data[1], 0);
                int z = tr.strToInt(data[2], 0);
                System.out.println(getData(x,y,z));
    as you can see unpacked.get(0) gives me 197|69|275 but then i use .split("|") and send each result to the strToInt i get a error and end up with 3 "0" how can that be?
     
  2. Offline

    nisovin

    The second parameter of the Integer.parseInt method is the radix, not an "ifNot" option. Unless you're using something besides base ten, you shouldn't be putting anything in there.

    Edit: ninjad.
     
  3. Offline

    Moon_werewolf

Thread Status:
Not open for further replies.

Share This Page