我正在创建一个简单的游戏,我偶然发现了一个我无法解决的错误。 尝试使用图形导入/绘制图像时会弹出错误:
Multiple markers at this line
- getCenterX cannot be resolved or is not a field
- getCenterY cannot be resolved or is not a field
- getCenterY cannot be resolved or is not a field
我非常确定我正确导入了所有内容:
// In the class "StartingClass"
private Robot robot;
private URL base;
// In the class "Robot"
private int centerX = 100;
private int centerY = 328;
@Override
public void paint(Graphics g) {
g.drawImage(character, robot.getCenterX()- 61, robot.getCenterY - 62, this);
}
@Override
public void start() {
robot = new Robot();
}
public int getCenterX() {
return centerX;
}
public int getCenterY() {
return centerY;
}
答案 0 :(得分:1)
robot.getCenterY
我认为问题在于此,因为getCenterY不是变量。它是方法getCenterY()的拼写错误。要修复,只需在末尾添加括号。 否则,请发布更多代码段,因为您提供的代码无法确定。