Results 1 to 7 of 7
  1. #1
    nikx_8_7 is offline Member
    Join Date
    Aug 2009
    Posts
    3
    Rep Power
    0

    Default Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

    i am making an application for a online test.... i hav stored question and ans in sql server 2005.
    But when i compare the correct ans with ans supplied by users i get following


    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at online1.actionPerformed(online1.java:685)
    at javax.swing.AbstractButton.fireActionPerformed(Unk nown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed (Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed (Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(Unknown Sour
    ce)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(U nknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unkno wn Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)




    Plz Help

  2. #2
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at online1.actionPerformed(online1.java:685)
    The top line of the stack trace tells you everything except the name of the field that is null. Look at your code...

  3. #3
    nikx_8_7 is offline Member
    Join Date
    Aug 2009
    Posts
    3
    Rep Power
    0

    Default

    :confused:
    i don't understand what you are saying ... can u plz elaborate???

  4. #4
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    282
    Rep Power
    6

    Default

    You get a NullPointerException, when you call a method on any reference variable which is not initialized, means its holding a null reference.

    For e.g.

    Java Code:
    public class MyClass{
      String s;
      public static void main(String arg[]){
           MyClass mc=new MyClass();
           System.out.println(s.length());  // will throw a nullpointerexception as variable s has not been initialized.
      }
    }
    So look at your code properly and make sure that you are not committing any such mistake.

  5. #5
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    282
    Rep Power
    6

    Default

    Sorry there was a small mistake in the code

    System.out.println(s.length());

    should be

    System.out.println(mc.s.length());

  6. #6
    nikx_8_7 is offline Member
    Join Date
    Aug 2009
    Posts
    3
    Rep Power
    0

    Default

    i get this exception when i try to compare 2 arrays which hold the records retrieved from sql server 2005....here's the code snippet...

    try
    {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con=DriverManager.getConnection("jdbc:odbc:A1","", "");
    st=con.createStatement();
    res=st.executeQuery("select * from store");

    while(res.next())
    {
    userans[i]=res.getString(1).trim();

    System.out.println(userans[i]);
    i++;
    }

    }
    catch(Exception fggf)
    {
    System.out.println("exception occurred2"+fggf);
    }
    l20.setText(String.valueOf(count1));

    //-------------------------gett---------------------------

    try
    {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con=DriverManager.getConnection("jdbc:odbc:A1","", "");
    st=con.createStatement();
    res=st.executeQuery("select * from ans");

    while(res.next())
    {
    getans[j]=res.getString(1).trim();
    System.out.println(getans[j]);
    j++;

    }
    }
    catch(Exception erb)
    {
    System.out.println(erb+" while getting original answers ");
    }

    for(int z=0;z<5;z++)
    {
    if(userans[z]==getans[z])
    counter++;
    }


    counter counts number of correct ans

  7. #7
    vkorenev is offline Member
    Join Date
    Aug 2009
    Location
    Kharkov, Ukraine
    Posts
    29
    Rep Power
    0

    Default

    at online1.actionPerformed(online1.java:685)
    This means that you should look at line 685 in online1.java.

Similar Threads

  1. Replies: 4
    Last Post: 06-07-2009, 01:59 AM
  2. Replies: 12
    Last Post: 05-26-2009, 02:48 PM
  3. Replies: 10
    Last Post: 01-29-2009, 09:00 AM
  4. Replies: 12
    Last Post: 10-05-2008, 07:52 AM
  5. Replies: 3
    Last Post: 01-29-2008, 02:37 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
  •