This site requires JavaScript, please enable it in your browser!
Greenfoot back
HoperAndDreemurr
HoperAndDreemurr wrote ...

2017/5/30

World.getObject() strange error

HoperAndDreemurr HoperAndDreemurr

2017/5/30

#
I am making a game where I need to access all of the Labels on the screen from my World (called Arena)
ArrayList<Label> kfls = getObjects(Label.class);
There is one error that I cannot expel, which is: incompatible types: no instances(s) of type variable(s) A exist so that java.util.List<A> conforms to java.util.ArrayList<Label>. If you could fix my error and also tell me why exactly this is happening that would be fantastic!
davmac davmac

2017/5/31

#
I suspect that means that "Label" is not a subclass of Actor? In that case, you are asking for a list of objects in the world of a type of object which cannot be in the world. (However, I'm not sure. The error message is certainly confusing...)
HoperAndDreemurr HoperAndDreemurr

2017/5/31

#
I tried adding a couple of them into the World (via addObject() ) but the error still persists. I am going to go to sleep now. Maybe the answer will come by next morning.
danpost danpost

2017/5/31

#
HoperAndDreemurr wrote...
I tried adding a couple of them into the World (via addObject() ) but the error still persists.
You might try this instead:
List<Label> kfls = getObjects(Label.class);
I do not know if it will help; but, it is worth a try.
HoperAndDreemurr HoperAndDreemurr

2017/5/31

#
Wow!!! Thanks, after changing ArrayList to List, I got another error instead relating to my imported java.awt.* extension for another unknown reason, then I changed java.awt.* to java.awt.Color, and everything worked fine. Thank you again. It would be cool to know what happened exactly, although I don't care about it that much. Maybe I will see this again when I am a programmer with more experience.
davmac davmac

2017/5/31

#
It would be cool to know what happened exactly
If you were importing java.awt.*, then you were implicitly importing java.awt.Label. That is what caused the error; Label in your code was referring to java.awt.Label, which is not an actor and therefore can't be in the world.
You need to login to post a reply.