Hi
Im having a problem with some code. Originally, the application was set into three packages (script, gui and control). I have changed is so there is a fourth called 'report'. Whenever I call upon anything in the report package though, there is a NullPointerException for the 'report' variable (which identifies the location of the report. The below part is where the problem occurs:
private void injuriesMouseClicked(java.awt.event.MouseEvent evt)
{
Injuries = true;
report.reportInfo();
}
In the above part both the report and Injuries variables are populated with the correct information
In some circumstances (this is the wierd thing), the reportInfo class is accessed, but when I try to retrieve the value of 'report' to check the value, the execution refuses to print out anything in the report.reportInfo class. But when I print out a random bit of text it prints it out fine. Whenever I try both it does nothing!! The code in report.reportInfo is below:
public class ReportData implements ScriptThread, Runnable
{
private DCWorkbenchGUI gui;
private VppController control;
private ComplexScript script;
//state variables for the script
public int publicDisorder = 0;
public int soldierInjuries = 0;
public int publicInjuries = 0;
public int civilanFireInjuries = 0;
public int civilanFireFatalities = 0;
public int soldierFatalities = 0;
public int suspectApprehension = 0;
public int baseDamage = 0;
public int pressCoverage = 0;
/**
* Constructor for the ReportData thread
*
* @param g the gui
* @param c the controller
* @param s the script
*/
public ReportData(DCWorkbenchGUI g, VppController c, ComplexScript s)
{
gui = g;
control = c;
script = s;
}
/**
* This method is that which will be invoked when the method is called upon
*/
public void run()
{
reportInfo();
}
/**
* Method to represent the action for the report information
*/
public void reportInfo()
{
System.out.println("reportInfo: ");
if (gui.Injuries = true)
{
String Injuries = ("Soldier Injuries (max 27): " + soldierInjuries +"\n" +
"Public Injuries (max 20): " + publicInjuries +"\n" +
"Civilian Emergency Services Injuries (max 10): " + civilanFireInjuries);
//display info dialog to the user
gui.scenInfo("The following information has been found by your assistant \n"+ Injuries,
"General Information",
script.currentTimeInSecs());
gui.Injuries = false;
}
EndReport();
}
}
*******************************************
The errors are below:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at dcw.report.ReportData.reportInfo(ReportData.java:5 9)
at dcw.gui.DCWorkbenchGUI.injuriesMouseClicked(DCWork benchGUI.java:234)
at dcw.gui.DCWorkbenchGUI.access$000(DCWorkbenchGUI.j ava:34)
at dcw.gui.DCWorkbenchGUI$1.mouseClicked(DCWorkbenchG UI.java:161)
at java.awt.AWTEventMulticaster.mouseClicked(AWTEvent Multicaster.java:253)
at java.awt.Component.processMouseEvent(Component.jav a:6044)
at javax.swing.JComponent.processMouseEvent(JComponen t.java:3265)
at java.awt.Component.processEvent(Component.java:580 6)
at java.awt.Container.processEvent(Container.java:205 8)
at java.awt.Component.dispatchEventImpl(Component.jav a:4413)
at java.awt.Container.dispatchEventImpl(Container.jav a:2116)
at java.awt.Component.dispatchEvent(Component.java:42 43)
at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4322)
at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:3995)
at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:3916)
at java.awt.Container.dispatchEventImpl(Container.jav a:2102)
at java.awt.Window.dispatchEventImpl(Window.java:2440 )
at java.awt.Component.dispatchEvent(Component.java:42 43)
at java.awt.EventQueue.dispatchEvent(EventQueue.java: 599)
at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:121)