Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Apr 25, 2006, 09:54 AM   #1
stadidas
macrumors regular
 
Join Date: Feb 2006
Location: Kent, United Kingdom
New Java Release Problem

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.
stadidas is offline   0 Reply With Quote
Old Apr 25, 2006, 10:04 AM   #2
Eraserhead
macrumors G4
 
Eraserhead's Avatar
 
Join Date: Nov 2005
Location: UK
Quote:
Originally Posted by stadidas
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.
__________________
Actually it does make sense. Man created god, so if we exist, He exists. - obeygiant
Eraserhead is online now   0 Reply With Quote
Old Apr 25, 2006, 12:29 PM   #3
mrichmon
macrumors 6502a
 
Join Date: Jun 2003
Quote:
Originally Posted by stadidas
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 is offline   0 Reply With Quote
Old Apr 25, 2006, 12:41 PM   #4
stadidas
Thread Starter
macrumors regular
 
Join Date: Feb 2006
Location: Kent, United Kingdom
OK I have also uploaded the new classes, AboutBox and Game.

If anyone has any idea which parts of the standard library I have sued which has been update then please let me know.
stadidas is offline   0 Reply With Quote
Old Apr 25, 2006, 12:48 PM   #5
mrichmon
macrumors 6502a
 
Join Date: Jun 2003
Quote:
Originally Posted by stadidas
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/...l#show(boolean)
mrichmon is offline   0 Reply With Quote
Old Apr 25, 2006, 12:55 PM   #6
MarkCollette
macrumors 65816
 
MarkCollette's Avatar
 
Join Date: Mar 2003
Location: Calgary, 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.
MarkCollette is offline   0 Reply With Quote
Old Apr 25, 2006, 02:46 PM   #7
stadidas
Thread Starter
macrumors regular
 
Join Date: Feb 2006
Location: 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.
stadidas is offline   0 Reply With Quote
Old Apr 25, 2006, 03:14 PM   #8
MarkCollette
macrumors 65816
 
MarkCollette's Avatar
 
Join Date: Mar 2003
Location: Calgary, Canada
Quote:
Originally Posted by stadidas
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.
MarkCollette is offline   0 Reply With Quote
Old Apr 25, 2006, 03:25 PM   #9
stadidas
Thread Starter
macrumors regular
 
Join Date: Feb 2006
Location: 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?
stadidas is offline   0 Reply With Quote
Old Apr 25, 2006, 03:25 PM   #10
bousozoku
Moderator emeritus
 
Join Date: Jun 2002
Location: Gone but not forgotten.
Quote:
Originally Posted by mrichmon
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/...l#show(boolean)
It's deprecation and deprecated, not depreciation and depreciated--retired, not discounted.
bousozoku is offline   0 Reply With Quote
Old Apr 25, 2006, 07:05 PM   #11
stadidas
Thread Starter
macrumors regular
 
Join Date: Feb 2006
Location: Kent, United Kingdom
So no-one knows how to change the Java compiler that XCode uses? Surely someone must!
stadidas is offline   0 Reply With Quote
Old Apr 25, 2006, 07:30 PM   #12
Thom_Edwards
macrumors regular
 
Join Date: Apr 2003
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/

Last edited by Thom_Edwards; Apr 25, 2006 at 07:37 PM.
Thom_Edwards is offline   0 Reply With Quote
Old Apr 25, 2006, 08:01 PM   #13
stadidas
Thread Starter
macrumors regular
 
Join Date: Feb 2006
Location: Kent, United Kingdom
Thanks! By changing the target Java compiler from default to 1.4.2 it's now running how it used to, thanks very much!
stadidas is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Safari 7.0.2 Java problem HiDeHo Mac Applications and Mac App Store 1 Mar 27, 2014 12:17 PM
Chrome on OS X -- Java plugin / Java 7 vs Java 6 Issue booyahbooyah Mac Applications and Mac App Store 4 May 31, 2013 10:13 AM
problem with java being blocked Apple souce Mac Applications and Mac App Store 10 Jan 12, 2013 12:49 AM
Java VisualVM Problem macuser1232 OS X 10.8 Mountain Lion 5 Nov 9, 2012 11:59 AM
Problem with java (VM) Buck1 Mac Basics and Help 2 Sep 2, 2012 10:28 AM

Forum Jump

All times are GMT -5. The time now is 06:21 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC