Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

bill_hai 华桑科技 开发组长/高级工程师/技术专家  2008-06-08 10:28:14
我做了一个cs结构的聊天程序,用了swing,hibernate。可是有时候会出现会出现下列异常,它也没说我程序的哪行出错,
我该怎么找错误啊。什么原因可能导致不报异常位置。
哪位仁兄帮帮忙,都困扰我好几天了。
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.plaf.basic.BasicTreeUI.paint(BasicTreeUI.java:1140)
at javax.swing.plaf.metal.MetalTreeUI.paint(MetalTreeUI.java:152)
at javax.swing.plaf.ComponentUI.update(ComponentUI.java:143)
at javax.swing.JComponent.paintComponent(JComponent.java:763)
at javax.swing.JComponent.paint(JComponent.java:1027)
at javax.swing.JComponent.paintToOffscreen(JComponent.java:5122)
at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:285)
at javax.swing.RepaintManager.paint(RepaintManager.java:1128)
at javax.swing.JComponent._paintImmediately(JComponent.java:5070)
at javax.swing.JComponent.paintImmediately(JComponent.java:4880)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:723)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:679)
at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:659)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:128)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
...全文
14911 点赞 收藏 18
写回复
18 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
ke_shi 2012-06-27
初来乍论坛,还望大家多多关照,多多指教。
回复
xiezongxun 2011-12-19
估计是你定义的表名与默认关键字是一样的!例如你的表名为“user”,而user是关键字,所以会出现这样的异常。。。
回复
Kevin-K先森 2011-08-27
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.plaf.basic.BasicTextUI.getPreferredSize(Unknown Source)
at javax.swing.plaf.basic.BasicTextAreaUI.getPreferredSize(Unknown Source)
at javax.swing.JComponent.getPreferredSize(Unknown Source)
at javax.swing.JTextArea.getPreferredSize(Unknown Source)
at javax.swing.ScrollPaneLayout.layoutContainer(Unknown Source)
at java.awt.Container.layout(Unknown Source)
at java.awt.Container.doLayout(Unknown Source)
at java.awt.Container.validateTree(Unknown Source)
at java.awt.Container.validate(Unknown Source)
at javax.swing.RepaintManager.validateInvalidComponents(Unknown Source)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)


这就没有哪一行啊··
回复
wwoo905 2011-04-27
StudentObjectStream obs=new StudentObjectStream();
List lst1=new ArrayList();
File f= new File(System.getProperty("user.dir")+"\\"+"student.obj");
if (f.exists())//当文件存在时,要先从文件中读出记录,再增加记录。
lst1=(List)obs.read1(System.getProperty("user.dir")+"\\"+"student.obj");
System.out.println(lst1.size());
Student s1=new Student(jComboBox1.getSelectedItem().toString(),jTextField1.getText(),jTextField2.getText(),jComboBox2.getSelectedItem().toString(),Integer.parseInt(jTextField3.getText()));
lst1.add(s1);
jComboBox1.setSelectedItem("计应");
jComboBox2.setSelectedItem("英语");
jTextField1.setText(null);
jTextField2.setText(null);
jTextField3.setText(null);
obs.write1(System.getProperty("user.dir")+"\\"+"student.obj", lst1);
请帮我看看这段代码哪错了。我的错误跟楼主一样
回复
youlong699 2011-03-26
发生了同样的问题,查到这篇老帖,看回复中有童鞋提到调用了updateUI导致,经检查确实如此,但是不调用又不行,会导致树叶的内容显示出现省略号,由于加载树叶启用了新线程,联想到swing的多线程机制,随后将updateUI()放入到 SwingUtilities.invokeLater()中进行,问题解决。
回复
zhangxinlan5 2010-08-09
也遇到同样问题,自己一直在查,
等待高手解决
回复 1
NJL_ILY_2009 2010-04-02
我也遇到此问题 谁人解答
回复
jingmaozhangjun 2010-03-18
是因为显示调用updateUI()的原因
回复
alksjdsadf 2009-12-29
我也遇到了同样的问题啊, 不知楼主是怎样解决的 , 能告知与否?
回复
yang6n 2008-08-19
LZ是不是调用了updateUI()来刷新啊,
回复
估计楼主没解决呢

我也碰到啦。。也是cs的程序连接数据库

最开始报

[Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.

我发现是那个数据库服务器的防火墙关啦后再连就报这个

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

还没解决正在找答案!
回复
lya121 2008-06-08
怎么会不报异常位置呢?
难道……
回复
East271536394 2008-06-08
java.lang.NullPointerException
为空指针,Exception
看下你new 没有呀,
没有出错的位置 ,就跟到程序走一次,
每一个地方都System.out.println()下,
慢慢来,总找的出来的,
回复
科學信仰 2008-06-08
括号里都可以点进去啊 基本是在paint方法中碰到的空指针 再看看吧
回复
lya121 2008-06-08
[Quote=引用 2 楼 pangxie 的回复:]
空指针异常,看看那个对象没有被初始化,如果用Netbeans或Eclipse根据输出提示找错误所在行
[/Quote]

人家都说了没报错误所在行。
你自己看嘛

反正我没看的到。
回复
lya121 2008-06-08
[Quote=引用 2 楼 pangxie 的回复:]
空指针异常,看看那个对象没有被初始化,如果用Netbeans或Eclipse根据输出提示找错误所在行
[/Quote]
回复
pangxie 2008-06-08
空指针异常,看看那个对象没有被初始化,如果用Netbeans或Eclipse根据输出提示找错误所在行
回复
发帖
Java SE
创建于2007-09-28

6.1w+

社区成员

Java 2 Standard Edition
申请成为版主
帖子事件
创建了帖子
2008-06-08 10:28
社区公告
暂无公告