Results 1 to 7 of 7
- 08-02-2009, 10:32 AM #1
Member
- Join Date
- Aug 2009
- Posts
- 3
- Rep Power
- 0
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
- 08-03-2009, 03:22 AM #2
The top line of the stack trace tells you everything except the name of the field that is null. Look at your code...Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at online1.actionPerformed(online1.java:685)
- 08-03-2009, 09:08 AM #3
Member
- Join Date
- Aug 2009
- Posts
- 3
- Rep Power
- 0
:confused:
i don't understand what you are saying ... can u plz elaborate???
- 08-03-2009, 09:30 AM #4
Senior Member
- Join Date
- Dec 2008
- Location
- Kolkata
- Posts
- 280
- Rep Power
- 5
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.
So look at your code properly and make sure that you are not committing any such mistake.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. } }
- 08-03-2009, 09:34 AM #5
Senior Member
- Join Date
- Dec 2008
- Location
- Kolkata
- Posts
- 280
- Rep Power
- 5
Sorry there was a small mistake in the code
System.out.println(s.length());
should be
System.out.println(mc.s.length());
- 08-03-2009, 03:35 PM #6
Member
- Join Date
- Aug 2009
- Posts
- 3
- Rep Power
- 0
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
- 08-03-2009, 08:58 PM #7
Member
- Join Date
- Aug 2009
- Location
- Kharkov, Ukraine
- Posts
- 29
- Rep Power
- 0
Similar Threads
-
[newbie] Exception in thread "AWT-EventQueue-0" java.lang.Error
By jon80 in forum New To JavaReplies: 4Last Post: 06-07-2009, 12:59 AM -
[newbie] Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException
By jon80 in forum New To JavaReplies: 12Last Post: 05-26-2009, 01:48 PM -
[SOLVED] pls help :S . "Exception in thread "AWT-EventQueue-0" java.lang.NullPointerE
By ara in forum New To JavaReplies: 10Last Post: 01-29-2009, 08:00 AM -
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
By iuna in forum AWT / SwingReplies: 12Last Post: 10-05-2008, 06:52 AM -
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
By hemanthjava in forum AWT / SwingReplies: 3Last Post: 01-29-2008, 01:37 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks