I ran the Main.java after you performed refactoring and found that there is an error message in the console. Steps to reproduce: 1. Run Main.java Expected Output: No error Actual Output: A NullPointerException error message is shown in the console. The details are as below: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: Cannot invoke "com.cs3343_Group16.greedySnake.model.Game.getMode()" because "this.game" is null at com.cs3343_Group16.greedySnake.action.UIPainting.actionPerformed(UIPainting.java:84) at java.desktop/javax.swing.Timer.fireActionPerformed(Timer.java:311) at java.desktop/javax.swing.Timer$DoPostEvent.run(Timer.java:243) at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318) at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:771) at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:722) at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:716) at java.base/java.security.AccessController.doPrivileged(AccessController.java:399) at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86) at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:741) at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203) at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124) at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113) at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109) at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
The bug is due to we added another constructor in the UIPainting class and deleted the initialization of the game field. We now added it back. The code implementation: private Game game=new Game();//add the initialization back