NullPointerException Error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Lost Prophet
    New Member
    • Mar 2008
    • 14

    NullPointerException Error

    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 NullPointerExce ption for the 'report' variable (which identifies the location of the report. The below part is where the problem occurs:

    private void injuriesMouseCl icked(java.awt. event.MouseEven t evt)
    {
    Injuries = true;

    report.reportIn fo();
    }

    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.reportIn fo 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.reportIn fo 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 civilanFireInju ries = 0;
    public int civilanFireFata lities = 0;
    public int soldierFataliti es = 0;
    public int suspectApprehen sion = 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(DCWo rkbenchGUI 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.prin tln("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): " + civilanFireInju ries);

    //display info dialog to the user
    gui.scenInfo("T he following information has been found by your assistant \n"+ Injuries,
    "General Information",
    script.currentT imeInSecs());
    gui.Injuries = false;
    }


    EndReport();

    }
    }

    *************** *************** *************

    The errors are below:

    Exception in thread "AWT-EventQueue-0" java.lang.NullP ointerException
    at dcw.report.Repo rtData.reportIn fo(ReportData.j ava:59)
    at dcw.gui.DCWorkb enchGUI.injurie sMouseClicked(D CWorkbenchGUI.j ava:234)
    at dcw.gui.DCWorkb enchGUI.access$ 000(DCWorkbench GUI.java:34)
    at dcw.gui.DCWorkb enchGUI$1.mouse Clicked(DCWorkb enchGUI.java:16 1)
    at java.awt.AWTEve ntMulticaster.m ouseClicked(AWT EventMulticaste r.java:253)
    at java.awt.Compon ent.processMous eEvent(Componen t.java:6044)
    at javax.swing.JCo mponent.process MouseEvent(JCom ponent.java:326 5)
    at java.awt.Compon ent.processEven t(Component.jav a:5806)
    at java.awt.Contai ner.processEven t(Container.jav a:2058)
    at java.awt.Compon ent.dispatchEve ntImpl(Componen t.java:4413)
    at java.awt.Contai ner.dispatchEve ntImpl(Containe r.java:2116)
    at java.awt.Compon ent.dispatchEve nt(Component.ja va:4243)
    at java.awt.Lightw eightDispatcher .retargetMouseE vent(Container. java:4322)
    at java.awt.Lightw eightDispatcher .processMouseEv ent(Container.j ava:3995)
    at java.awt.Lightw eightDispatcher .dispatchEvent( Container.java: 3916)
    at java.awt.Contai ner.dispatchEve ntImpl(Containe r.java:2102)
    at java.awt.Window .dispatchEventI mpl(Window.java :2440)
    at java.awt.Compon ent.dispatchEve nt(Component.ja va:4243)
    at java.awt.EventQ ueue.dispatchEv ent(EventQueue. java:599)
    at java.awt.EventD ispatchThread.p umpOneEventForF ilters(EventDis patchThread.jav a:273)
    at java.awt.EventD ispatchThread.p umpEventsForFil ter(EventDispat chThread.java:1 83)
    at java.awt.EventD ispatchThread.p umpEventsForHie rarchy(EventDis patchThread.jav a:173)
    at java.awt.EventD ispatchThread.p umpEvents(Event DispatchThread. java:168)
    at java.awt.EventD ispatchThread.p umpEvents(Event DispatchThread. java:160)
    at java.awt.EventD ispatchThread.r un(EventDispatc hThread.java:12 1)
  • Stang02GT
    Recognized Expert Top Contributor
    • Jun 2007
    • 1206

    #2
    Welcome to the Scripts,

    Your question appears to be Java related. For future reference try to post language specific questions in the appropriate forums. This way you will get a faster/better answer.


    Thanks and Enjoy!

    Comment

    Working...