• 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

Cannot properly get ints from String Array

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey all! I'm trying to run a chat application where a client (aside of chatting) can ask to calculate the factorial of a number.
For the number 12, the client types for example "factorial:12"

When I get the numbers I put them into an array and then convert them into a string, ultimately converting them back into ints,
afterwards which I use to calculate the factorial.

Sadly it's not working out and it's giving me a NumberFormatException at this line:

n = Integer.parseInt(getallen);


Here's the main part of the code:



This is what I can in Eclipse as error:

12Exception in thread "main" java.lang.NumberFormatException: For input string: "[2]"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at InstantMessagingApplication.ServerApp$HandleAClient.run(ServerApp.java:209)
at InstantMessagingApplication.ServerApp.<init>(ServerApp.java:95)
at InstantMessagingApplication.ServerApp.main(ServerApp.java:32)

Stored array numbers: 1
Stored array numbers: 2




Can anybody help me out on this one?
All suggestions are welcome!

Thanks!
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The error message says it all:

Exception in thread "main" java.lang.NumberFormatException: For input string: "[2]"



First it tells you that what you passed to parseInt wasn't an integer (you may have suspected that was what it was telling you). Then it goes on to tell you exactly what you passed to parseInt; as you can see, it isn't an integer.
 
reply
    Bookmark Topic Watch Topic
  • New Topic