PDA

View Full Version : New Java Release Problem




stadidas
Apr 25, 2006, 08:54 AM
Since I upgraded to Apple's fourth release of Java my application gets a warning in XCode when it's compiled which says "uses or overrides a deprecated API". When I try to run the compiled app it quits without doing anything. I've uploaded a copy of the source code of the offending class here: Class (http://www.matefeedkillrepeat.com/Asset_Monitor.java).

If anyone can tell me how to fix this I'd be very grateful. I'm sure it's probably something stupid, but I never know how to fix anything.



Eraserhead
Apr 25, 2006, 09:04 AM
Since I upgraded to Apple's fourth release of Java my application gets a warning in XCode when it's compiled which says "uses or overrides a deprecated API". When I try to run the compiled app it quits without doing anything. I've uploaded a copy of the source code of the offending class here: Class (http://www.matefeedkillrepeat.com/Asset_Monitor.java).

If anyone can tell me how to fix this I'd be very grateful. I'm sure it's probably something stupid, but I never know how to fix anything.
It doesn't compile for me (as I don't have all the files)... Surely XCode tells you the line of the problem?

If not try using javac in Terminal.

mrichmon
Apr 25, 2006, 11:29 AM
If anyone can tell me how to fix this I'd be very grateful. I'm sure it's probably something stupid, but I never know how to fix anything.

It's a warning. With new releases of Java certain parts of the standard libraries are redesigned. The old interfaces are left in the standard library and marked as depreciated. This means that they are there and will work now but may be removed in a future version of Java. Effectively, a depreciated warning is a message to the developer that there is a new interface to the functions they are calling and though the code will work now, the developer should start using the new interface since the old interface might be removed in the future.

As far as the class you have posted. I doubt you will get much help since the posted class depends on your "AboutBox" class which you have not posted.

stadidas
Apr 25, 2006, 11:41 AM
OK I have also uploaded the new classes, AboutBox (http://www.matefeedkillrepeat.com/AboutBox.java) and Game (http://www.matefeedkillrepeat.com/Game.java).

If anyone has any idea which parts of the standard library I have sued which has been update then please let me know.

mrichmon
Apr 25, 2006, 11:48 AM
If anyone has any idea which parts of the standard library I have sued which has been update then please let me know.

The javac option -depreciation will output the lines that use a depreciated API.

In this code, the aboutBox.show() call is depreciated.

According to the Java 1.5 API documentation the show() method has been depreciated and should be replaced by a call to setVisible(true).

See http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Component.html#show(boolean)

MarkCollette
Apr 25, 2006, 11:55 AM
I don't have my Mac here, so I can't try anything out, but I have some unrelated suggestions:

- Don't initialise variables outside of your constructor. Do it all in the constructor. This affects things like Serialization, and having class hierarchies.

- Don't have button1, button2, button3... Use an array, or give your JButtons real names.

- Asset_Monitor extends JFrame, and so is a JFrame, yet you have some other JFrame frame variable that you're putting all your stuff into.

-You make a lot of inner class ActionListeners. Instead, I make one ActionListener, and in actionPerformed I do:

if( event.getSource() == button1 ) { ... }
else if( event.getSource() == New ) { ... }
else if( event.getSource() == OpenLog ) { ... }

- If you're parsing several inputs, and on an error putting some message into a JOptionPane, then instead of doing one at a time, check all problems, and add all messages into a Vector, and then put that into the JOptionPane. That way if the user makes several mistakes, they'll get all the error messages at once, and can fix them all, instead of frustratingly re-entering data over and over.

- Put all your application state variables, like balance, weeks, days, daysLeft, perWeek, perDay into a separate object. It's good programming to have separation between your View code (Swing JFrame) and your Model (balance, weeks, etc.).

- Try not to have global variables, especially when it's unnecessary. Push temp1, temp2, temp3 down into openLog, and make openLog pass them as parameters into parseLog. Also, give them meaningful names.

stadidas
Apr 25, 2006, 01:46 PM
OK thanks those are some great tips.

I changed show to setVisible and the warning has gone away. The app however still won't launch correctly. The terminal in XCode gives this error:

[Session started at 2006-04-25 19:42:28 +0100.]
[JavaAppLauncher Error] CallStaticVoidMethod() threw an exception
Exception in thread "main" java.lang.UnsupportedClassVersionError: Asset_Monitor (Unsupported major.minor version 49.0)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:219)
at apple.launcher.LaunchRunner.loadMainMethod(LaunchRunner.java:55)
at apple.launcher.LaunchRunner.run(LaunchRunner.java:84)
at apple.launcher.LaunchRunner.callMain(LaunchRunner.java:50)
at apple.launcher.JavaApplicationLauncher.launch(JavaApplicationLauncher.java:52)

Asset Monitor has exited with status 0.

I'm not really sure what to do with that, but hopefully some of you will know.

MarkCollette
Apr 25, 2006, 02:14 PM
OK thanks those are some great tips.

I changed show to setVisible and the warning has gone away. The app however still won't launch correctly. The terminal in XCode gives this error:

[Session started at 2006-04-25 19:42:28 +0100.]
[JavaAppLauncher Error] CallStaticVoidMethod() threw an exception
Exception in thread "main" java.lang.UnsupportedClassVersionError: Asset_Monitor (Unsupported major.minor version 49.0)

Glad to help.

This means that the Java bytecode that the compiler emitted is a newer version of Java than the runtime supports.

So, most likely, you're compiling with Java 1.5, but trying to run your program under Java 1.4 or 1.3.

stadidas
Apr 25, 2006, 02:25 PM
I thought it might be something like that. I remember reading on the release notes it se the default compiler to 1.5 How do I change it to get it to compile using 1.4.2?

bousozoku
Apr 25, 2006, 02:25 PM
The javac option -depreciation will output the lines that use a depreciated API.

In this code, the aboutBox.show() call is depreciated.

According to the Java 1.5 API documentation the show() method has been depreciated and should be replaced by a call to setVisible(true).

See http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Component.html#show(boolean)

It's deprecation and deprecated, not depreciation and depreciated--retired, not discounted. :)

stadidas
Apr 25, 2006, 06:05 PM
So no-one knows how to change the Java compiler that XCode uses? Surely someone must!

Thom_Edwards
Apr 25, 2006, 06:30 PM
try compiling with -source or -target option. like, -source 1.4, or -target 1.4

not sure, exactly. never been in that situation. but you can look at http://mindprod.com/jgloss/javacexe.html#COMMANDLINE.

that's where i found this in about 30 seconds using dear old google. hope it helps. i went ahead and did the search because i didn't know--at least i learned something!

EDIT: did a little more searching. this link is more specific to xcode: http://cordney.com/2005/09/24/java-5-setup-on-os-x/

stadidas
Apr 25, 2006, 07:01 PM
Thanks! By changing the target Java compiler from default to 1.4.2 it's now running how it used to, thanks very much!