The screenshot as it is works. If I instead try to iterate over the snakeParts list, it all goes to hell. (The commented code is used instead of calling each element over and over for that.)
What am I doing wrong?
Error Trace
It's all Greek down here, but I think it's a NoSuchElement Exception. But why?
Exception in Application start method
Exception in thread "main" java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:973)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:198)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.util.NoSuchElementException
at java.base/java.util.ArrayList$Itr.next(ArrayList.java:999)
at com.codegym.games.snake.Snake.draw(Snake.java:30)
at com.codegym.games.snake.SnakeGame.drawScene(SnakeGame.java:23)
at com.codegym.games.snake.SnakeGame.createGame(SnakeGame.java:28)
at com.codegym.games.snake.SnakeGame.initialize(SnakeGame.java:14)
at com.codegym.engine.cell.Game.start(Game.java:68)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:919)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$11(PlatformImpl.java:449)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$9(PlatformImpl.java:418)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:417)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
Why can't i Iterate?
Under discussion
Comments (1)
- Popular
- New
- Old
You must be signed in to leave a comment
Guadalupe Gagnon
4 November 2019, 17:29
Iterator.next() calls the next value. You use it twice with:
game.setCellValue(Iterator.next().x, Iterator.next().y.....)
This is going to create problems first in that x and y will be from different objects, and more seriously will crash the program when the iterator has an odd number of objects.
0