Results 1 to 5 of 5
  1. #1
    kumar_ravi is offline Member
    Join Date
    Jul 2012
    Location
    Brisbane, Australia
    Posts
    4
    Rep Power
    0

    Default I can not solve this "NullPointerException"

    Hi,
    i am trying to do access the database table records using swing event handling but after pressing the button it is showing exception. i dont know what is going wrong. here is my code:

    private void DisplayAllButtonActionPerformed(java.awt.event.Act ionEvent evt) {

    try {

    String SQL = "SELECT * FROM OCCUPANTS";
    rs = stmt.executeQuery( SQL );

    while( rs.next( )) {
    int id_col = rs.getInt("ID");
    String id=Integer.toString(id_col);
    String room =rs.getString("ROOM");
    String occupant = rs.getString("OCCUPANT");

    DisplayArea.setText( id + " " + room + " " + occupant);
    }
    }
    catch ( SQLException err ) {
    System.out.println( err.getMessage( ) );
    }
    }

    Fallowing is the exception:

    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at wumpus.WumpusGUI.DisplayAllButtonActionPerformed(W umpusGUI.java:264)
    at wumpus.WumpusGUI.access$300(WumpusGUI.java:16)
    at wumpus.WumpusGUI$4.actionPerformed(WumpusGUI.java: 164)
    at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:2018)
    at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2341)
    at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(BasicButtonListener.java:252)
    at java.awt.Component.processMouseEvent(Component.jav a:6505)
    at javax.swing.JComponent.processMouseEvent(JComponen t.java:3321)
    at java.awt.Component.processEvent(Component.java:627 0)
    at java.awt.Container.processEvent(Container.java:222 9)
    at java.awt.Component.dispatchEventImpl(Component.jav a:4861)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2287)
    at java.awt.Component.dispatchEvent(Component.java:46 87)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4832)
    at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:4492)
    at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:4422)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2273)
    at java.awt.Window.dispatchEventImpl(Window.java:2719 )
    at java.awt.Component.dispatchEvent(Component.java:46 87)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.j ava:703)
    at java.awt.EventQueue.access$000(EventQueue.java:102 )
    at java.awt.EventQueue$3.run(EventQueue.java:662)
    at java.awt.EventQueue$3.run(EventQueue.java:660)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(ProtectionDomain.java:76)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(ProtectionDomain.java:87)
    at java.awt.EventQueue$4.run(EventQueue.java:676)
    at java.awt.EventQueue$4.run(EventQueue.java:674)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 673)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:244)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:163)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:151)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:147)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:139)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:97)
    BUILD SUCCESSFUL (total time: 28 seconds)

    Thanks.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default Re: I can not solve this "NullPointerException"

    Which line is line #264?

    kind regaards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    kumar_ravi is offline Member
    Join Date
    Jul 2012
    Location
    Brisbane, Australia
    Posts
    4
    Rep Power
    0

    Default Re: I can not solve this "NullPointerException"

    this is the line no 264.
    rs = stmt.executeQuery( SQL );

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default Re: I can not solve this "NullPointerException"

    Most likely 'stmt' is null; you can find out for sure if you add a few System.out.println( ... ) calls that print out the value of 'stmt'

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    Join Date
    Nov 2012
    Posts
    1
    Rep Power
    0

    Default hello world :)

    Hello , my name is Yohan and I found this forum and its members really nice!

Similar Threads

  1. Replies: 5
    Last Post: 12-21-2011, 07:44 PM
  2. Replies: 11
    Last Post: 03-16-2011, 12:36 AM
  3. How can I solve "void cannot be dereferenced" error?
    By fervent07 in forum New To Java
    Replies: 2
    Last Post: 04-05-2010, 09:54 PM
  4. How to solve this "Fixtures code" error exception?
    By makerror in forum New To Java
    Replies: 4
    Last Post: 12-02-2009, 03:45 AM
  5. Replies: 1
    Last Post: 10-20-2008, 08:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •