File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can't add to ArrayList within switch statement?

 
Ray Michaels
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 210
Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Try removing the () from the case number like this case 1: not case (1):


 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64188
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It might be helpful if you explained what "isn't working" means.
 
Ray Michaels
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic