gpt4 book ai didi

java - 在我的 Swing Goose 类中出现 NullPointerException

转载 作者:行者123 更新时间:2023-12-01 19:12:18 27 4
gpt4 key购买 nike

我认为我的 _holder 和/或 _gooseActionnull....以下是 _holder 所在的相关代码/类_gooseAction 被实例化:

Goose.java

public class Goose {
//Goose class
private ActionHolder _holder;
private gooseAction _gooseAction;

public Goose (JPanel container, GooseAction action, ActionHolder holder) {
super(container);
_holder = holder;
_gooseAction = _holder.getAction();
_gooseAction = action;
}

public void react() {
_gooseAction.stop();
_holder.getAction();
_gooseAction = _holder.getAction();
_gooseAction.setObjective(this);
_gooseAction.start();
}

ControlPanel.java

public class ControlPanel {
//top level class
public ControlPanel() {
super();
_holder = new ActionHolder(_moveAction);
_drawingPanel = new DrawingPanel(_holder);
_gooseAction = new GooseAction();
_doNothing = new StopBehavior();
_kingGoose = new FollowBehavior(_kingGoose);
}

private GooseAction _gooseAction;
private ActionHolder _holder;

public class ActionHolder {
private GooseAction _GooseAction;
public ActionHolder(GooseAction Action) {
_gooseAction = Action;
}
public void setAction(GooseAction GooseAction) {
_gooseAction = GooseAction;
}
public GooseAction getAction() {
return _gooseAction.copy();
}
}

public class ActionButton extends JButton {
public ActionButton(String string, boolean b, GooseAction action, ActionHolder holder) {
super(string, b);
_holder = holder;
_gooseAction = action;

}
}

private class ActionListener implements ChangeListener {

public ActionListener(GooseAction action) {
}

public void stateChanged(ChangeEvent e) {
_holder.setAction(_gooseAction);
}
}

最佳答案

if(_holder == null) System.out.println("_holder is null");
if(_gooseAction == null) System.out.println("_gooseAction is null");

关于java - 在我的 Swing Goose 类中出现 NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8003049/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com