为什么我用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 编写一个聊天室程序 程序没有问题 可是一测试结果就出现上面的提示 正常的话会谈出聊天窗口的 这是为什么???
请高手帮忙 急急急!!!!!!!!!!!!!!谢谢了!!! 展开
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 编写一个聊天室程序 程序没有问题 可是一测试结果就出现上面的提示 正常的话会谈出聊天窗口的 这是为什么???
请高手帮忙 急急急!!!!!!!!!!!!!!谢谢了!!! 展开
2个回答
展开全部
看看 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的缘故 要用个布局器吧
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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询