aspose file tools*
The moose likes Beginning Java and the fly likes Cannot properly get ints from String Array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Cannot properly get ints from String Array" Watch "Cannot properly get ints from String Array" New topic
Author

Cannot properly get ints from String Array

Andrew Servania
Greenhorn

Joined: Jun 13, 2011
Posts: 1
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
Bartender

Joined: Oct 14, 2005
Posts: 18669
    
    8

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.
 
wood burning stoves
 
subject: Cannot properly get ints from String Array