piranha999
Technical User
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)
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)