| Author |
Can't add to ArrayList within switch statement?
|
Ray Michaels
Greenhorn
Joined: Apr 09, 2011
Posts: 2
|
|
I'm having trouble inserting objects to an ArrayList within a switch statement. Before entering the switch, the add function works fine. Here's the code:
Can anyone advise me as to why the add command within the switch statement isn't working and what to do to make it work?
|
 |
mike ryan
Ranch Hand
Joined: Aug 08, 2010
Posts: 210
|
|
Hi,
Try removing the () from the case number like this case 1: not case (1):
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56233
|
|
|
It might be helpful if you explained what "isn't working" means.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Ray Michaels
Greenhorn
Joined: Apr 09, 2011
Posts: 2
|
|
Nothing gets added to the ArrayList... the size doesn't increase after the add statement within the switch and the values added don't show when I print out the contents of the ArrayList. Don't know how to explain it any other way... Removing parenthesis from around the case values did not fix it .
Edit: I've tried removing the switch and using an if instead, but it does not make a difference.
Edit 2: I figured out the problem was that I was instantiating the ArrayList after everytime I tried to add an appointment within the switch.
|
 |
 |
|
|
subject: Can't add to ArrayList within switch statement?
|
|
|