• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cannot properly get ints from String Array

 
Andrew Servania
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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!
 
Paul Clapham
Sheriff
Pie
Posts: 20724
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic