Java: Can't get value from LinkedList to another class
Go to solution
Solved by WanderingFool,
I don't know if these are the exact problems, and MrSuperb talks about an issue that I will repeat, because it is a bit one.
So the first issue that I see (well more of an comment and fix). Don't just use plain LinkLink in Java. You should be setting the default types.
LinkedList<Brick> brickList = new LinkedList<Brick>(); ///How it should be
This way you will actually be able to get Bricks out of the list instead of casting it later on.
Now for the second issue, which seems like you might need to brush up on how variables are handled in Java.
public Object addBrick(int brick_positionX, int brick_positionY, int brick_lenght, int brick_height, boolean isVisible) { System.out.println("Brick.addBrick();"); Brick brick = new Brick(); //Creating a new brick this.brick_positionX = brick_positionX; //Setting the current brick, the the brick variable to the value this.brick_positionY = brick_positionY; //See above this.brick_lenght = brick_lenght; this.brick_height = brick_height; this.isVisible = isVisible; return brick; //You are now returning the brick variable...but you have not even changed a single thing, so the variables will be all default values (ie 0 for ints and false for booleans) }
MrSuperB's solution is correct though. And as Ciccioo said, you really should have revisited the original post...it mentions the biggest fault which is the addBrick, which needs to be fixed first
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now