Bug 665 - NullPointerException error message of UIPainting class when running the Main.java
Summary: NullPointerException error message of UIPainting class when running the Main....
Status: RESOLVED FIXED
Alias: None
Product: CS3343 2021/22 Group16 Greedy Snake
Classification: Unclassified
Component: System section (show other bugs)
Version: Ver 3.0
Hardware: PC Windows
: --- critical
Assignee: Baron Qu
URL:
Depends on:
Blocks:
 
Reported: 2021-12-06 17:50 HKT by WANG Yiwen
Modified: 2021-12-06 18:02 HKT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description WANG Yiwen 2021-12-06 17:50:49 HKT
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)
Comment 1 LI Ruoxin 2021-12-06 18:02:00 HKT
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