• Post Reply Bookmark Topic Watch Topic
  • New Topic

adding to an arraylist from an if conditional?  RSS feed

 
Max Lechich
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator




This is for a maze game with a gui. up is a button on the gui, and there are also buttons for down, left, right, etc.
I need to have a command list to give to the maze solving method(I need to do it this way for a project).
I can't figure out how to add characters to comList for some reason. Nothing works. I've tried every weird way I could think of.
I'm having a huge brainfart today, I am working on 2 hours of sleep.

p.s. The method compiles, I didn't show the entire thing so there are brackets are missing. I just showed the part that doesn't work.

p.p.s Did I post in the wrong forum?
 
Ankit Garg
Sheriff
Posts: 9610
37
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this a serious question?? If yes then this is not the correct forum and we'll move it for you...
 
Max Lechich
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's a serious question. Sorry.

My first time on the forum, I guess I got lost
 
Ankit Garg
Sheriff
Posts: 9610
37
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a forum just for fun created for 1st April, so its not your fault that you got lost ...
 
Ankit Garg
Sheriff
Posts: 9610
37
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you getting a NullPointerException in addCommand method??
 
Max Lechich
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no exceptions, it just doesn't add anything to the arraylist.

It apparently adds it in the if block, because

works exactly how I want it to, but when I hit another button(that prints the command list and then uses it to solve) the arraylist is empty again.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you creating another instance of the class? That's the only possible way the list would be empty. It would be trivial to find out if you're adding to the same list by dumping the list object and checking its toString code.
 
Max Lechich
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh dear. Talk about a brainfart.
I moved the arraylist out of the action class like you said and it works now.
What's wrong with me?

Anyway, thanks for the help.






 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!