BBC (Brian's Boot Camp)

Not to be confused with the British Broadcasting Corporation, the BBC will focus on Brian's fast paced journey of the mastery of the Java programming language.

Monday, February 21, 2005

Another small milestone

While I'm waiting for Outlook to launch, I'll throw this up. At the beginning of the 21 Days book, the author states that the portability of Java's code allows developers to Write one, debug everywhere; funny. So far, any code that I've used for any assignments, examples, or exercises has worked fine on my laptop (where I'm using Eclipse) or on my Mac (where I'm using vim and the command line tools). Until chapter 9 which introduces Swing. The classes would compile fine on either platform, but when I ran them on OS X, I'd get the following output:

Exception in thread "main" java.lang.Error: Do not use FormatFrame.add() use FormatFrame.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 FormatFrame.(FormatFrame.java:24)
at FormatFrame.main(FormatFrame.java:29)

shell returned 1

I managed to track the problem down to the line add(panel); which added a JPanel to JFrame FormatFrame. Based on the error, it looked like the runtime environment wanted the getContentPane().add() method used rather than the add() method. Sure enough; altered that line of code and it compiled and ran successfully. Huzzah! On to chapter 10...

1 Comments:

Blogger Sten said...

You must be using Java 1.5 on your laptop (if so, good job) since that is a pre-1.5 error. Since macs at still at 1.4 that's why you saw that.

But yeah, good job tracking it down.

12:58 PM  

Post a Comment

<< Home