显示了一个Java nullpointer异常,此文本字段在另一帧中定义为静态,我从Chat.textField类的名称调用它, 但是会显示此异常。
Java
while (true) {
Chat.textField.addKeyListener(new KeyAdapter() //here is the problem because an exception is shown
{
public void keyPressed(KeyEvent e)
{
if (e.getKeyCode() == KeyEvent.VK_ENTER)
{
emri="Albanit";
for (int i = 0; i < maxClientsCount; i++) {
if (threads[i] != null) {
try {
threads[i].os.writeUTF(name + emri);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
}
}
});
}