• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 11
Netbeans IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why this is giving me error

 
Ranch Hand
Posts: 250
1
Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
where should i write it can you help me with that
 
isslam akkilah
Greenhorn
Posts: 11
Netbeans IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i tried this but nothing works

 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic