Results 1 to 8 of 8
- 04-07-2011, 03:55 PM #1
Senior Member
- Join Date
- Dec 2010
- Location
- The Hague
- Posts
- 114
- Rep Power
- 0
Stack (collection) to int via String
this is the problem[], but how can i get this 9 to an int?Java Code:public int getOldXIndex() { oldXIndex.pop(); String s = oldXIndex.toString(); int i= Integer.parseInt(s); return i; }
Error: Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "[9]"
- 04-07-2011, 04:06 PM #2
What is oldXIndex? What happens when you call its toString()? What are you doing with the value you pop from it?
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 04-07-2011, 04:33 PM #3
Senior Member
- Join Date
- Dec 2010
- Location
- The Hague
- Posts
- 114
- Rep Power
- 0
Hi,
oldXIndex? its the Stack variable and it holds a [10].
With the pop it becomes [9]
When i call to string it seems to get "[9]" and thats when the numberformat exception comes, because of [].
The question would be, how do i get a good int of an Item in a Stack collection.
Maybe there are other ways.
Kind regards,
André
- 04-07-2011, 04:36 PM #4
I'm pretty sure you don't want to be using the Stack's toString(). I'm still not clear what you're trying to do- are you trying to print the last item popped? The item at the top? The size? Something else?
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 04-07-2011, 04:37 PM #5
Senior Member
- Join Date
- Dec 2010
- Location
- The Hague
- Posts
- 114
- Rep Power
- 0
The item after a pop, so this is the last item.
- 04-07-2011, 04:40 PM #6
Senior Member
- Join Date
- Dec 2010
- Location
- The Hague
- Posts
- 114
- Rep Power
- 0
Think away the pop. I want to convert the last item of a Stack into an int.
- 04-07-2011, 04:42 PM #7
Are you looking for the peek() method?
Recommended reading: Stack (Java Platform SE 6)How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 04-07-2011, 05:16 PM #8
Senior Member
- Join Date
- Dec 2010
- Location
- The Hague
- Posts
- 114
- Rep Power
- 0
Similar Threads
-
Stack (push/pop/top)
By sehudson in forum New To JavaReplies: 1Last Post: 03-08-2011, 02:40 AM -
Stack
By kayln in forum EclipseReplies: 0Last Post: 03-04-2011, 08:14 PM -
How big is the stack??
By mgeno216 in forum New To JavaReplies: 6Last Post: 03-04-2011, 08:04 AM -
Counting vowles in a collection of String objects
By sunde887 in forum New To JavaReplies: 4Last Post: 01-18-2011, 07:22 AM -
Need help please – implementing a stack!
By sfe23 in forum New To JavaReplies: 0Last Post: 02-24-2009, 03:19 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks