In my program I need to convert a String to Int.
String str = new String(request.getData());
String [] setting = str.split(" ");
String bs = setting[1];
The value of bs is 1024, I use System.out.println to test it, and it displays on the screen with "1024".
But when I use
int blockSize = Integer.parseInt(bs);
it will return an exception point to the line of Integer.parseInt :
Exception in thread "main" java.lang.NumberFormatException: For input string: "1024"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:458)
at java.lang.Integer.valueOf(Integer.java:554)
Can someone help me to solve it? Thanks.
stringvalue not aintegerthat's why this error. make suresetting[postion]is anintegervalue. i mean like "somevalue".bs.length()would probably be helpful, and possibly even a loop over the characters outputting their character code:for (char ch : bs.toCharArray() ) { System.out.println(Integer.toHexString(ch)); }