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

2020/2/20

Keep getting error :/

footpickle footpickle

2020/2/20

#
java.lang.ClassCastException: counter2 cannot be cast to plane2 at Scroller.scroll(Scroller.java:133) at BossWorld.scroll(BossWorld.java:55) at BossWorld.act(BossWorld.java:44) at greenfoot.core.Simulation.actWorld(Simulation.java:573) at greenfoot.core.Simulation.runOneLoop(Simulation.java:506) at greenfoot.core.Simulation.runContent(Simulation.java:193) at greenfoot.core.Simulation.run(Simulation.java:183) java.lang.ClassCastException: counter2 cannot be cast to plane2 at Scroller.scroll(Scroller.java:133) at BossWorld.scroll(BossWorld.java:55) at BossWorld.act(BossWorld.java:44) at greenfoot.core.Simulation.actWorld(Simulation.java:573) at greenfoot.core.Simulation.runOneLoop(Simulation.java:506) at greenfoot.core.Simulation.runContent(Simulation.java:193) at greenfoot.core.Simulation.run(Simulation.java:183) java.lang.ClassCastException: counter2 cannot be cast to plane2 at Scroller.scroll(Scroller.java:133) at BossWorld.scroll(BossWorld.java:55) at BossWorld.act(BossWorld.java:44) at greenfoot.core.Simulation.actWorld(Simulation.java:573) at greenfoot.core.Simulation.runOneLoop(Simulation.java:506) at greenfoot.core.Simulation.runContent(Simulation.java:193) at greenfoot.core.Simulation.run(Simulation.java:183) this is annoying pls help me?
footpickle footpickle

2020/2/20

#
I don't understand why this is happening. it comes up whenever I run my thing.
danpost danpost

2020/2/20

#
footpickle wrote...
I don't understand why this is happening. it comes up whenever I run my thing.
My guess is because you modified the Scroller class (which probably should never have been done) with some erroneous code at line 133.
footpickle footpickle

2020/2/20

#
I don't understand. I DID use your code from your project (very helpful by the way) but I don't understand what is wrong.
footpickle footpickle

2020/2/20

#
Wait, I think I did edit line 133. Can you please put the correct code to see if mine is wrong? Also, what does "erroneous" mean? Sorry, I'm new and honestly kinda dumb :/
footpickle footpickle

2020/2/20

#
It's saying this is the problem :
for (Object obj : world.getObjects(null))
        {
            Plane2 plane2 = (Plane2) obj;
            plane2.setLocation(plane2.getX()-dsx, plane2.getY()-dsy);
        }
and this
private void scroll(){
        int rate=5;
        //determine offsets and scroll
        int dsx=0;
        int dsy=0;
        if(Greenfoot.isKeyDown("up")) dsy--;
        if(Greenfoot.isKeyDown("down")) dsy++;
        myscroller.scroll(0,dsy*rate);
    }
AND also this
public void act() 
    {
        scroll();
    } 
danpost danpost

2020/2/21

#
footpickle wrote...
It's saying this is the problem: << Code Omitted >>
Is that the code you added to the Scroller class? Restore the class to its original code (remove all your edits from the class). Only under very special circumstances should it be modified -- and that is only to rectify issues that cannot be dealt with elsewhere within the scenario. I only ever had to modify it once -- and that was to allow the setLocation call be redirected on smooth moving actors.
footpickle footpickle

2020/2/22

#
I had to because the class my plane extends is called controllables. Should I change it to have a capital letter? Or should it have stayed as Actors?
danpost danpost

2020/2/22

#
footpickle wrote...
I had to because the class my plane extends is called controllables. Should I change it to have a capital letter? Or should it have stayed as Actors?
It should remain as Acto.
footpickle footpickle

2020/2/22

#
Turns out I'm an idiot. I changed the "Actor actor = (actor)" to "Plane2 plane2 = (plane2)" without realizing that wasn't how it worked. Thanks for your help anyway!
You need to login to post a reply.