为什么我用JAVA编程会出现这样的错误提示

java.lang.Error:DonotuseChatJFrame.add()useChatJFrame.getContentPane().add()insteadat... java.lang.Error: Do not use ChatJFrame.add() use ChatJFrame.getContentPane().add() instead
at javax.swing.JFrame.createRootPaneException(JFrame.java:465)
at javax.swing.JFrame.addImpl(JFrame.java:491)
at java.awt.Container.add(Container.java:307)
at ChatJFrame.<init>(ChatJFrame.java:19)
at ChatServerSocket.<init>(ChatServerSocket.java:27)
at ChatServerSocket.main(ChatServerSocket.java:45)
Exception in thread "main"
我用的工具是netbeans 编写一个聊天室程序 程序没有问题 可是一测试结果就出现上面的提示 正常的话会谈出聊天窗口的 这是为什么???
请高手帮忙 急急急!!!!!!!!!!!!!!谢谢了!!!
展开
 我来答
只生大0E
2007-06-03
知道答主
回答量:13
采纳率:0%
帮助的人:0
展开全部
看看 java API 文档
The JFrame class is slightly incompatible with Frame. Like all other JFC/Swing top-level containers, a JFrame contains a JRootPane as its only child. The content pane provided by the root pane should, as a rule, contain all the non-menu components displayed by the JFrame. This is different from the AWT Frame case. As a conveniance add and its variants, remove and setLayout have been overridden to forward to the contentPane as necessary. This means you can write:

frame.add(child);

And the child will be added to the contentPane. The content pane will always be non-null. Attempting to set it to null will cause the JFrame to throw an exception. The default content pane will have a BorderLayout manager set on it. Refer to RootPaneContainer for details on adding, removing and setting the LayoutManager of a JFrame

估计是你没有Layout的缘故 要用个布局器吧

参考资料: http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JFrame.html

百度网友acd2d0d
2007-05-25 · TA获得超过1488个赞
知道大有可为答主
回答量:1355
采纳率:100%
帮助的人:0
展开全部
Do not use ChatJFrame.add() use ChatJFrame.getContentPane().add() instead
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式