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

2013/5/15

"Modificationscreen cannot be cast to terrainone"

1
2
mezboycalday mezboycalday

2013/5/15

#
jones get away
Gevater_Tod4711 Gevater_Tod4711

2013/5/15

#
You are using the class skisbutton in both of the worlds. To fix that you should check if the world is either one or the other class using the instanceof operator. You can use it like this:
if (getWorld() instanceof Modificationscreen) {
    //your current world class is Modificationscreen;
}
else if (getWorld() instanceof terrainone) {
    //your world class is terrainone;
}
mattjonescalday mattjonescalday

2013/5/15

#
Gevater_Tod4711 - where exactly should I put this?
mezboycalday mezboycalday

2013/5/15

#
hi
Gevater_Tod4711 Gevater_Tod4711

2013/5/15

#
You have to use this in your skisbutton class. If you are shure what worldclass you have at the moment you will not get exceptions while casting it (Because you know what cast you have to use).
mezboycalday mezboycalday

2013/5/15

#
sure*
mattjonescalday mattjonescalday

2013/5/15

#
Thanks very much - i will test it now
mattjonescalday mattjonescalday

2013/5/15

#
Gevater I will have to test it tomorrow lesson has finished and I got to go to form - yay! Thanks for your help.
mattjonescalday mattjonescalday

2013/5/16

#
Hi guys I have just got back from testing it and it still has a problem with it saying there is an index out of bounds exception on line 254 of the terrainone code below
        int selectiontracksValue = ((tracksbutton) getObjects(tracksbutton.class).get(0)).getshared();
Any ideas
davmac davmac

2013/5/16

#
You have no tracksbutton objects in the world, so getObjects(...) returns an empty list, and .get(0) is then invalid (you can't get the first item from an empty list).
mattjonescalday mattjonescalday

2013/5/16

#
But how then do I get the variable from the tracksbutton actor?
jamesnidd jamesnidd

2013/5/16

#
davmac hurry up jones is getting impatient
jamesnidd jamesnidd

2013/5/16

#
davmac you there?????
davmac davmac

2013/5/16

#
You either need to have a tracksbutton instance in the world, so that getObjects(...) returns a list with an item in it, or you need to maintain a separate reference to the tracksbutton object (in a variable), set that at some point, and use it instead of getObjects(...).
You need to login to post a reply.
1
2