Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

stadidas

macrumors regular
Original poster
Feb 27, 2006
243
0
Kent, United Kingdom
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.

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

macrumors G4
Nov 3, 2005
10,434
12,250
UK
stadidas said:
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.

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

macrumors 6502a
Jun 17, 2003
873
3
stadidas said:
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.
 

mrichmon

macrumors 6502a
Jun 17, 2003
873
3
stadidas said:
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

macrumors 68000
Mar 6, 2003
1,559
36
Toronto, Canada
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

macrumors regular
Original poster
Feb 27, 2006
243
0
Kent, United Kingdom
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

macrumors 68000
Mar 6, 2003
1,559
36
Toronto, Canada
stadidas said:
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

macrumors regular
Original poster
Feb 27, 2006
243
0
Kent, United Kingdom
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

Moderator emeritus
Jun 25, 2002
15,719
1,893
Lard
mrichmon said:
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. :)
 

Thom_Edwards

macrumors regular
Apr 11, 2003
240
0
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.