0
프로그래밍 수업 소개를위한 프로젝트에서 작업 중이며 약간의 문제가 발생했습니다. 우리는 사이드 스크롤러를 만들고 있는데, 지금 스코어 카운터에서 일하고 있습니다. 내 문제는 (모든 프레임 한 번 호출됩니다) act 메서드 이외의 다른 카운터 클래스에 대한 참조를 만들려고 할 때 null 포인터 예외 오류가 발생합니다. 내 코드가 들어있는 zip 파일을 here에 다운로드 할 수 있습니다.nullPointerException 오류 greenfoot
편집 :
public class HeroMissile extends Missiles
{
/**
* Act - do whatever the HeroMissile wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
move(8);
remove();
}
public void remove() {
if(isTouching(Drone.class)) {
removeTouching(Drone.class);
getWorld().addObject(new Explosion(), getX(), getY());
getWorld().removeObject(this);
addScore();
return;
}
}
public void addScore() {
City cityWorld = (City) getWorld();
**Counter scoreCounter = cityWorld.getCounter();**
scoreCounter.add(1);
}
}