한 클래스에서 다른 클래스에서 액세스하려는 개인 변수를 선언했습니다. 그러나 문제는 객체 flappyBird
을 전달할 때 null이라는 것입니다. 내가해야 할 변화는 무엇입니까?NPE 방지 : 다른 클래스의 개인 객체에 액세스
FlappyBird.java : 개체가 여기에 생성
public class FlappyBird implements ActionListener, KeyListener, MouseListener
{
private static FlappyBird flappyBird;
public static void main(String[] args)
/* CREATE INSTANCE OF FLAPPBIRD() */
{
flappyBird = new FlappyBird();
}
public static FlappyBird getBird() {
return flappyBird;
}
public static void paint(Graphics phics) {
...
}
GraphicRenderer.java : 여기
public class GraphicsRenderer extends JPanel
{
private static FlappyBird bird = new FlappyBird();
public void paint(Graphics phics)
{
// Generate game graphics by calling paint() in FlappyBird.
bird.getBird();
super.paint(phics);
bird.paint(phics);
}
}
는'getBird()'라는있는 방법이 없습니다와'setBird'/기타 부품이 매우 잘못하고 의미 – Li357
, 내 나쁜 입력하지 않은 @AndrewL하지 않는 권리 – Ben