• Post Reply Bookmark Topic Watch Topic
  • New Topic

java.lang.NumberFormatException: For input string: "1" error  RSS feed

 
Greenhorn
Posts: 11
Java Netbeans IDE PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why this is giving me error

 
Ranch Hand
Posts: 250
1
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try calling trim() on the line, as it may include some special line break character.
 
isslam akkilah
Greenhorn
Posts: 11
Java Netbeans IDE PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
where should i write it can you help me with that
 
isslam akkilah
Greenhorn
Posts: 11
Java Netbeans IDE PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i tried this but nothing works

 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Start by printing the line before parsing it. System.out.printf("Line = \u201c%s\u201d%n", line);//test
\u201c%s\u201d will give the line surrounded by “quote marks” ← like that, so you can see the length of the line. If that doesn't help, try printing each character with its hex values:-
System.out.print("Line as characters = ");//test
for (char c : line.toCharArray())//test
{//test
    System.out.printf("0x%04x", (int)c);//test
}//test
System.out.println();//test

If 1 is an ASCII character it should come out as 0x0031. I am not absolutely certain that the (int) cast is necessary.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And you have forgotten to make sure to close your Reader after use. Potentially serious mistake.
 
isslam akkilah
Greenhorn
Posts: 11
Java Netbeans IDE PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that is going to print all the line i need only the line that have int value and i need it as string
 
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
isslam akkilah wrote:that is going to print all the line i need only the line that have int value and i need it as string

Campbell is suggesting you do that not as a solution to your problem, but as a means to figure out the solution.

It is entirely possible the string does not contain what you think it does. Using his technique, you can look and see what is REALLY in your string. If it does contain what you think it does, then you can remove that line and look elsewhere. If it doesn't, that will let you see what is in it, and then you can determine a course of action.

The point it that until you KNOW (and by know I really mean know, not just assume you know), you can't fix it.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!