Bug 701 - When trying to move empty cell, NullPointer exception is thrown
Summary: When trying to move empty cell, NullPointer exception is thrown
Status: RESOLVED FIXED
Alias: None
Product: Chess Game - Group 24
Classification: Unclassified
Component: GUI (show other bugs)
Version: unspecified
Hardware: PC Mac OS
: Normal normal
Assignee: Assan Kozhin
URL:
Depends on:
Blocks:
 
Reported: 2022-11-06 13:28 HKT by sskawle2-c
Modified: 2022-11-28 02:20 HKT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description sskawle2-c 2022-11-06 13:28:05 HKT
Steps to Reproduce:
1.	Execute App.java
2.	Click on any empty cell on the board

Expected Results: 
Move should be invalid and ignored.

Actual Results:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: Cannot invoke "chess.chess.Gui.GuiPiece.getYp()" because "chess.chess.Gui.Gui.selectedPiece" is null
	at chess.chess.Gui.Gui$3.mouseReleased(Gui.java:136)
	at java.desktop/java.awt.Component.processMouseEvent(Component.java:6616)
	at java.desktop/java.awt.Component.processEvent(Component.java:6381)
	at java.desktop/java.awt.Container.processEvent(Container.java:2266)
	at java.desktop/java.awt.Window.processEvent(Window.java:2056)
	at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:4991)
	at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2324)
	at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2780)
	at java.desktop/java.awt.Component.dispatchEvent(Component.java:4823)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:775)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:720)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:714)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:97)
	at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:747)
	at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
	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:744)
	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 Assan Kozhin 2022-11-19 16:37:25 HKT
Quick fix related to GUI. Simple if statement to check if currently selected is null in
`public void mouseReleased(MouseEvent e)` in Gui.java.