线程“ Thread-2”中的异常java.lang.NullPointerException如何修复

时间:2019-06-13 15:42:28

标签: java

显示了一个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();
                            }

                          }

                          }
                    }
                  }
                });




              }

0 个答案:

没有答案