[英]Class method in enhanced for loop
I need to draw my buttons in the screen, but when using the for loop enhanced, 我需要在屏幕上绘制按钮,但是当使用for循环增强功能时,
public void update(){
for(Button bt: button){
bt.update();
}
}
an error is pointed in the 3rd line (code box above). 在第三行(上面的代码框)中指出了错误。 I don't know what is wrong, neither an alternative way to update/draw the buttons. 我不知道出了什么问题,也没有更新/绘制按钮的替代方法。 I tried using the "normal for loop", and the same line is marked. 我尝试使用“常规for循环”,并标记了同一行。
the console output below: 控制台输出如下:
Exception in thread "Thread-0" java.lang.NullPointerException
at gameState.FirstScreenState.update(FirstScreenState.java:55)
at main.GamePanel.update(GamePanel.java:96)
at main.GamePanel.run(GamePanel.java:71)
at java.lang.Thread.run(Thread.java:745)
Your button
collection/array contains a null
. 您的button
集合/数组包含null
。
I strongly recommend renaming button
to buttons
. 我强烈建议将button
重命名为buttons
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.