1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

New Java Release Problem

Discussion in 'Mac Programming' started by stadidas, Apr 25, 2006.

  1. macrumors regular

    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.
  2. macrumors G4


    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.
  3. macrumors 6502a

    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.
  4. macrumors regular

    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.
  5. macrumors 6502a

    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)
  6. macrumors 65816


    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.
  7. macrumors regular

    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.
  8. macrumors 65816


    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.
  9. macrumors regular

    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?
  10. Moderator emeritus

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

    So no-one knows how to change the Java compiler that XCode uses? Surely someone must!
  12. macrumors regular

  13. macrumors regular

    Thanks! By changing the target Java compiler from default to 1.4.2 it's now running how it used to, thanks very much!

Share This Page