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:5 9)
    at dcw.gui.DCWorkb enchGUI.injurie sMouseClicked(D CWork benchGUI.java:2 34)
    at dcw.gui.DCWorkb enchGUI.access$ 000(DCWorkbench GUI.j ava:34)
    at dcw.gui.DCWorkb enchGUI$1.mouse Clicked(DCWorkb enchG UI.java:161)
    at java.awt.AWTEve ntMulticaster.m ouseClicked(AWT Event Multicaster.jav a:253)
    at java.awt.Compon ent.processMous eEvent(Componen t.jav a:6044)
    at javax.swing.JCo mponent.process MouseEvent(JCom ponen t.java:3265)
    at java.awt.Compon ent.processEven t(Component.jav a:580 6)
    at java.awt.Contai ner.processEven t(Container.jav a:205 8)
    at java.awt.Compon ent.dispatchEve ntImpl(Componen t.jav a:4413)
    at java.awt.Contai ner.dispatchEve ntImpl(Containe r.jav a:2116)
    at java.awt.Compon ent.dispatchEve nt(Component.ja va:42 43)
    at java.awt.Lightw eightDispatcher .retargetMouseE vent( Container.java: 4322)
    at java.awt.Lightw eightDispatcher .processMouseEv ent(C ontainer.java:3 995)
    at java.awt.Lightw eightDispatcher .dispatchEvent( Conta iner.java:3916)
    at java.awt.Contai ner.dispatchEve ntImpl(Containe r.jav a:2102)
    at java.awt.Window .dispatchEventI mpl(Window.java :2440 )
    at java.awt.Compon ent.dispatchEve nt(Component.ja va:42 43)
    at java.awt.EventQ ueue.dispatchEv ent(EventQueue. java: 599)
    at java.awt.EventD ispatchThread.p umpOneEventForF ilter s(EventDispatch Thread.java:273 )
    at java.awt.EventD ispatchThread.p umpEventsForFil ter(E ventDispatchThr ead.java:183)
    at java.awt.EventD ispatchThread.p umpEventsForHie rarch y(EventDispatch Thread.java:173 )
    at java.awt.EventD ispatchThread.p umpEvents(Event Dispa tchThread.java: 168)
    at java.awt.EventD ispatchThread.p umpEvents(Event Dispa tchThread.java: 160)
    at java.awt.EventD ispatchThread.r un(EventDispatc hThre ad.java:121)
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    [QUOTE=Lost Prophet]

    You have to carefully read the stack trace insead of throwing your hands up in the
    air. NullPointer exceptions are sitting ducks (ref: r035198x) when you surround
    them with the relevant debug System.out.prin tln() statements. This is the quilty
    one:

    Code:
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at dcw.report.ReportData.reportInfo(ReportData.java:59)
    At line 59 in your reportInfo() method something is null which it shouldn't be.
    It's debugging time.

    kind regards,

    Jos

    Comment

    Working...