Bug 641 - Java Object Null Exception when viewResult is run before the Function Process was run
Summary: Java Object Null Exception when viewResult is run before the Function Process...
Status: RESOLVED FIXED
Alias: None
Product: 2021 CS3343 Hall Admission System
Classification: Unclassified
Component: System Section (show other bugs)
Version: unspecified
Hardware: PC Windows
: Normal minor
Assignee: Azim
URL:
Depends on:
Blocks:
 
Reported: 2021-12-04 16:12 HKT by amble3232
Modified: 2021-12-04 16:13 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 amble3232 2021-12-04 16:12:04 HKT
Background:
I am doing the unit testing in Eclipse 2021-06 (4.20.0) on method viewResult() in HallSystem class. 
In testHallSystem(), when I try to run the viewResult() before processing the application. 

Steps to Reproduce:
1. Run the package with testHall_Admission
2. Run the method “void testViewResult” in testViewResult class

Actual result:
After the run the above steps, the system returns the error message “Cannot invoke "HallAdmissionSystem.ProcessApplication.getFinalResult()" because "this.processApplication" is null”. 

Expected result:
I expect the system will show “Waiting for processing to finish” if I view the result before the processing is done.
Comment 1 newbie 2021-12-04 16:12:46 HKT
The system should show “waiting for processing to finish” or “need to run process function”, instead of error of null. 

I will pass it to the developer to solve this error.
Comment 2 Azim 2021-12-04 16:13:29 HKT
As the set of process objects have not been created, so the system cannot output any result. But as the code is to run “Display.runDisplay("All Result", content, false);” and will not check if the process function has been run successfully. Therefore the ArrayList is null. 

To solve the showing empty ArrayList problem, a check if the sets of process objects are created needed to be implemented.

Solution:
===============
public void viewResult() {
	if(processApplication != null){
		String content = processApplication.getFinalResult();

		Display.runDisplay("All Result", content, false);
	}
	else {
		String content = "Waiting for processing to finish.";
		Display.runDisplay("All Result",content , false);

	}
}