Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getting an error "Exception in thread "AWT-EventQueue-0" java.lang.NullPointerExcept"

 
abhijeet shrivastava
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ranchers,

I am getting an error while executing a swing application.on the click of a button,I am capturing the inputs passed by an user and passing them to my another programme,but i am getting the following error

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

code for actionperformed method is as follows.

public void actionPerformed(ActionEvent e)
{
if ("submit".equals(e.getActionCommand()))
{
variables = new HashMap(); // declared the swing class.
variables.put("ServiceURL",url.getText());
variables.put("Value",ssn.getText());
variables.put("CallingAppRole",prtcpnt_id.getText());
variables.put("Life Event Code",life_evnt_cd.getText());
variables.put("Envoirnment",envoirnment.getSelectedItem());
WSTestHarness testHarness = new WSTestHarness();
testHarness.setgui_swing(variables);
testHarness.executeTestSession();
}
}





Thanks in advance.

Regards,
Abhijeet Shrivastava
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at the full stack trace. It should tell you in which line the NPE occurs, which should make it rather obvious which variable is null.
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
everytime i got one of those errors, it was because i was trying to
compare or modify a variable without actually declaring it first.

like for instance:



you'll get a null pointer exception, not in the event queue, because
you didnt call it in the actionlistener or mouse/key.

but it is a similar incident.

post the whole code, and I could try to help you further.

Justin
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Justin Fox:
everytime i got one of those errors, it was because i was trying to
compare or modify a variable without actually declaring it first.


Just to get the terminology straight, in your example code the theField variable *is* declared, but not *initialized*.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic