多线程 java.lang.NullPointerException
 Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at javax.swing.plaf.basic.BasicListUI.paintImpl(BasicListUI.java:266)
    at javax.swing.plaf.basic.BasicListUI.paint(BasicListUI.java:240)
    at javax.swing.plaf.ComponentUI.update(ComponentUI.java:161)
    at javax.swing.JComponent.paintComponent(JComponent.java:780)
    at javax.swing.JComponent.paint(JComponent.java:1056)
    at javax.swing.JComponent.paintToOffscreen(JComponent.java:5219)
    at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1572)
    at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1495)
    at javax.swing.RepaintManager.paint(RepaintManager.java:1265)
    at javax.swing.JComponent._paintImmediately(JComponent.java:5167)
    at javax.swing.JComponent.paintImmediately(JComponent.java:4978)
    at javax.swing.RepaintManager$4.run(RepaintManager.java:824)
    at javax.swing.RepaintManager$4.run(RepaintManager.java:807)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
    at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:807)
    at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:782)
    at javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:731)
    at javax.swing.RepaintManager.access$1300(RepaintManager.java:64)
    at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1720)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

我写了个socket通信的小程序,,每次启动一个客户端就创建一个线程专门用来读取Server回复的信息,主线程用来往Server发信息。

有时 ,当我启动到第多个客户端时就会报出该异常,但是程序还是正常运行的。。只是在该客户端控制台输出了这些异常信息,有时一个一个关闭客户端时也会报该异常,

而这些不是我的代码里的东西,,求指导。这是异常是关于什么的。??

4个回答

lhs472194266
Haisen大王 貌似确实关于updateUI。。可以不清楚为什么
大约 5 年之前 回复

多线客户运行时,导致空指针异常,能运行说明还可以,

记住一件事:没被new过的对象如果为null。那么他的所有方法都不可用。
例如 现在有个方法是获取User对象的如getUser();
那么如果你这样用:User u= getUser();
如果getUser()返回null。那么u没被初始化。你不能用User类里的任何方法。如果用了就报

java.lang.NullPointerException错误。你自己看看。你哪里这样用了。
所以很多时候在使用一个类的方法时,都会判断下是否为null先

lhs472194266
Haisen大王 这个我也百度到了
大约 5 年之前 回复

开启多个客户端的时候弹出空指针异常,应该是对象空引用,或者对象创建了尚未new

空指针异常,有的对象没有new。或者等于null

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐