Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error runnning program using javx.swing in jcreator

 
Mitchell Mock
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am a beginner using one of O'Reillys beginning java. One of the first examples in the book causes the following error from trying to run this Java program.


Exception in thread "main" java.lang.Error: Do not use javax.swing.JFrame.add() use javax.swing.JFrame.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 HelloJava.main(HelloJava.java:37)

I am using jCreator 3.5 It runs fine in Textpad fine but I need to get it to work in jCreator

It complies in both
 
Campbell Ritchie
Sheriff
Pie
Posts: 48984
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you.

Wlecome aboard.

I think you need to check the version of JDK your JCreator is using. In J2SE5.0 you can say JFrame.add(), but in older versions you had to say JFrame.getContentPane().add().
Your JCreator might be using J1.4, in which case you need to alter the path in JCreator.
CR
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15288
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error tells you exactly what you should do: Do not use javax.swing.JFrame.add() use javax.swing.JFrame.getContentPane().add() instead... :roll:
 
Stephen Boston
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mitchell,

JCreator installs its own JDK. It may be different from the one you installed.

If you go to the configure menu and select options and then Profiles you can see what JDK it is using. You can also change the profile (or add a new one) to point to the newer version of the JDK you have installed.

HTH!
 
Mitchell Mock
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help
I updated to 1.5 Jre. I thought I had it but it was 1.4


Thanks again
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic