Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ItemListener Problem

Status
Not open for further replies.

piranha999

Technical User
Oct 8, 2001
8
AT
Can anyone figure out why i cant invoke Graphics operations in itemStateChanged() ? This is my code

package seccon;

import java.awt.event.*;
import java.awt.*;
import java.util.*;
import java.lang.*;

public class MyItemListener extends Canvas implements ItemListener{

private Vector deutsch, englisch;

public MyItemListener() {
deutsch = MakeHash.buildVectorDeutsch();
englisch = MakeHash.buildVectorEnglisch();
}

public void itemStateChanged(ItemEvent e){
int s = java.lang.Integer.parseInt(e.getItem().toString());
String t = BuildFrame.Auswahl.getItem(s);
//System.out.println(t);
int i = 0;
for (Enumeration enu = deutsch.elements(); enu.hasMoreElements();){
if (enu.nextElement().toString().equals(t)){
Graphics g = getGraphics();
g.drawString(deutsch.elementAt(i).toString(),10,20);
}
i++;
}
}

}

and is throwin this Exception if Event occurres:

Exception occurred during event dispatching:
java.lang.NullPointerException
at seccon.MyItemListener.itemStateChanged(MyItemListener.java:38)
at java.awt.List.processItemEvent(List.java:932)
at java.awt.List.processEvent(List.java:901)
at java.awt.Component.dispatchEventImpl(Component.java:2593)
at java.awt.Component.dispatchEvent(Component.java:2497)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:339)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:131)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:98)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:85)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top