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

2021/10/9

create a actor in a actor error?

Aaron-aid Aaron-aid

2021/10/9

#
everytime i load this code i get this error java.lang.NullPointerException at enemy.enemyimage(enemy.java:32) at enemy.act(enemy.java:21) import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class enemy here. * * @author (your name) * @version (a version number or a date) */ public class enemy extends Actor { GreenfootImage enemyimg; public enemy enemy1; /** * Act - do whatever the enemy wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { enemyimage(); getImage().scale(200, 200); if (isTouching(player.class)) { } } void enemyimage() { enemyimg = getImage(); enemy1.setImage(enemyimg); enemy1.setLocation(0,0); getWorld().addObject(enemy1, 30, 30); } }
Aaron-aid Aaron-aid

2021/10/9

#
bruh im a dumb, i realise i need to do enemy1= new enemy smh
You need to login to post a reply.