Hello! I'm trying to create a chunk of java which allows me to call classes depending on strings called from an array - however, I can't seem to get it to work, unfortunately. If anyone could help I'd be most grateful, I've included the code I've hashed out so far...
public class ProcrastinatorPanel extends JPanel {
String[] room = {
"Hallway", "Bathroom", "Study",
"Bedroom", "Dining Room", "Living Room",
"Kitchen", "Playroom", "Bathroom", "Garage" };
int roomNumber = 0;
public ProcrastinatorPanel() {
Hallway.hallway = new Hallway();
Class roomClass = Class.forName(room[roomNumber]);
}
}
Hallway
? – Thilo Jun 12 '13 at 18:57Hallway
that the classloader can find (which in this case means it's not in the default package). Use the fully qualified name. – Brian Roach Jun 12 '13 at 18:58Hallway
needs to be in the discouraged default package. Or you need to specify a package name. – Thilo Jun 12 '13 at 18:59hallway
could be a static field ofHallway
. – arshajii Jun 12 '13 at 19:00