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

2018/2/22

Creating a String of the class name

JimmyJimJams JimmyJimJams

2018/2/22

#
Is it possible to assign the class name of an actor to a string? if so ow would you do it.
danpost danpost

2018/2/22

#
Actor actor = getObjects(Actor.class).get(0); // get actor reference
String type = actor.getClass().getName(); // put class name of actor to a string
You will most probably be getting the actor reference some other way.
JimmyJimJams JimmyJimJams

2018/2/22

#
Im getting the error for getObjects it is: cannot find symbol - method getObjects(java.lang.Class<greenfoot.Actor>)
danpost danpost

2018/2/22

#
JimmyJimJams wrote...
Im getting the error for getObjects it is: cannot find symbol - method getObjects(java.lang.Class<greenfoot.Actor>)
You are probably using it in an Actor subclass. Try:
String type = this.getClass().getName();
You need to login to post a reply.