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

2021/5/28

idk what i must to do

mariq_rasyid29 mariq_rasyid29

2021/5/28

#
in the terminal show like this
ava.lang.NullPointerException
	at titan1.act(titan1.java:10)
	at greenfoot.core.Simulation.actActor(Simulation.java:567)
	at greenfoot.core.Simulation.runOneLoop(Simulation.java:530)
	at greenfoot.core.Simulation.runContent(Simulation.java:193)
	at greenfoot.core.Simulation.run(Simulation.java:183)
here is the titan 1 class code
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import javax.swing.JOptionPane;

public class titan1 extends proplv1
{
    public int Score=0;

    public void act() {
        titanjatoh();
        getWorld().showText("Score: "+String.valueOf(Score), 50, 10);
        if(getWorld() != null && !getWorld().getObjects(pelurulevi.class).
        isEmpty() &&cektitan())
            kena();          

    }  

    public boolean cekjatoh(){
        Actor batas1=getOneObjectAtOffset(0, 0, batas1.class);
        return(batas1!=null);
    }

    public void  titanjatoh(){
        setLocation(getX(), getY()+1);
        Actor batas1=getOneObjectAtOffset(0, 0, batas1.class);
        if (batas1!=null){
            getWorld().removeObject(this); 
            //JOptionPane.showMessageDialog(null, "GAME OVER");
            // Greenfoot.setWorld(new Menu());
        }
    }

    public boolean cektitan(){
        Actor pelurulevi=getOneIntersectingObject(pelurulevi.class);
        return(pelurulevi!=null);
    }

    public void kena(){
        Actor pelurulevi = getOneIntersectingObject(pelurulevi.class);
        if (pelurulevi != null){

            getWorld().removeObject(pelurulevi);
            getWorld().removeObject(this); Score+=10;
            pointitan1();

        }
    }

    public void pointitan1(){
             Score++;
            Score = Score + 10;
        }
    }


danpost danpost

2021/5/28

#
mariq_rasyid29 wrote...
in the terminal show like this
java.lang.NullPointerException
at titan1.act(titan1.java:10)
...
This happens when the titanjatoh method removes the titan1 object from the world, where after getWorld will return a null value. Insert after line 9 the following:
if (getWorld() == null) return;
After that, you can remove "getWorld() != null && " from line 11
mariq_rasyid29 mariq_rasyid29

2021/5/28

#
Ohhh ya and the Score not increased too Weird, syntax no error
danpost danpost

2021/5/28

#
mariq_rasyid29 wrote...
Ohhh ya and the Score not increased too Weird, syntax no error
Are you saying you are good, now?
mariq_rasyid29 mariq_rasyid29

2021/5/29

#
yeah for this
mariq_rasyid29 wrote...
in the terminal show like this
ava.lang.NullPointerException
	at titan1.act(titan1.java:10)
	at greenfoot.core.Simulation.actActor(Simulation.java:567)
	at greenfoot.core.Simulation.runOneLoop(Simulation.java:530)
	at greenfoot.core.Simulation.runContent(Simulation.java:193)
	at greenfoot.core.Simulation.run(Simulation.java:183)
here is the titan 1 class code
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import javax.swing.JOptionPane;

public class titan1 extends proplv1
{
    public int Score=0;

    public void act() {
        titanjatoh();
        getWorld().showText("Score: "+String.valueOf(Score), 50, 10);
        if(getWorld() != null && !getWorld().getObjects(pelurulevi.class).
        isEmpty() &&cektitan())
            kena();          

    }  

    public boolean cekjatoh(){
        Actor batas1=getOneObjectAtOffset(0, 0, batas1.class);
        return(batas1!=null);
    }

    public void  titanjatoh(){
        setLocation(getX(), getY()+1);
        Actor batas1=getOneObjectAtOffset(0, 0, batas1.class);
        if (batas1!=null){
            getWorld().removeObject(this); 
            //JOptionPane.showMessageDialog(null, "GAME OVER");
            // Greenfoot.setWorld(new Menu());
        }
    }

    public boolean cektitan(){
        Actor pelurulevi=getOneIntersectingObject(pelurulevi.class);
        return(pelurulevi!=null);
    }

    public void kena(){
        Actor pelurulevi = getOneIntersectingObject(pelurulevi.class);
        if (pelurulevi != null){

            getWorld().removeObject(pelurulevi);
            getWorld().removeObject(this); Score+=10;
            pointitan1();

        }
    }

    public void pointitan1(){
             Score++;
            Score = Score + 10;
        }
    }


but the scores not increased
danpost danpost

2021/5/29

#
mariq_rasyid29 wrote...
but the scores not increased
I am quite sure it is -- for that titan1 object. A different (or new) titan1 object would not show it (at least, none in your world would unless you added the same one back into the world).
You need to login to post a reply.