Java trouble

Discussion in 'Mac Programming' started by Zion Grail, Sep 28, 2004.

  1. macrumors regular

    Joined:
    Dec 24, 2002
    Location:
    Chicagoland
    #1
    Ever since I got the Java update I can't seem to run any of my classwork Java programs. No matter what I do, I get this error:

    Exception in thread "main" java.lang.NoClassDefFoundError

    Even in a simple HelloWorld! program I get this error. All of my programs, even ones that worked before, have started behaving like this.

    Anyone else have this kind of problem?

    *EDIT*

    Even the ready-to-compile java files I got form the book's CD are acting like this!!
     
  2. macrumors 603

    jeremy.king

    Joined:
    Jul 23, 2002
    Location:
    Fuquay Varina, NC
    #2
    How exactly are you trying to run these? Inside an IDE, from command line?

    remember to compile your .java file first using javac and then run it with the java command (no extension on the file to be run)

    For example
    PHP:
    public class HelloWorld
    {
      public static 
    void main(String[] args)
      {
        
    System.out.println("I love my mac.");
      }
    }
    from terminal:

    javac HelloWorld.java

    this creates HelloWorld.class, and then

    java HelloWorld

    If this is completely obvious, I apologize, but every once and a while I brainfart and run the .java file through the java command and whoopsy...same problem

    Good Luck
     
  3. macrumors 603

    Joined:
    Mar 2, 2002
    #3
    http://www.apple.com/downloads/macosx/apple/

    If you're not running the latest version of Java, do that. There are Java 1.4.2 Update 2 and Update 1 links there. If those don't help, go through pages 2, 3, 4, etc. at the bottom of the page of the link above to find the Java 1.4.1 update (for Panther).
     
  4. TEG
    macrumors 604

    TEG

    Joined:
    Jan 21, 2002
    Location:
    Langley, Washington
    #4
    That is how he got the problem, the update caused It. I've been having a similar problem when compiling. However, no problems with exitsting java apps. I'm just hoping Apple can get Java 5.0 (1.5) out quickly.

    TEG
     
  5. thread starter macrumors regular

    Joined:
    Dec 24, 2002
    Location:
    Chicagoland
    #5
    Fixed it, somewhat

    I can't be sure if it's the update or what, but I've found the problem - my classpath is blank. Nothin' in there. Gone.

    I had to find where Java keeps it's classes on my system and manually set it, and I have to tell my system to inclde whatever current directory I've put my projects in my going to the command line, going to the directory i'm using, and typing

    export CLASSPATH=$CLASSPATH:.

    Then, to run anything in that directly, I *STILL* need to use the command

    java -cp $CLASSPATH:. InsertClassNameHere

    Then it works.

    This is damn annoying, Apple. How did such a huge mistake get by you?
     
  6. macrumors 603

    jeremy.king

    Joined:
    Jul 23, 2002
    Location:
    Fuquay Varina, NC
    #6
    You need to set your CLASSPATH. Its not Apples responsibility. If you want it to be more permanant, look into editing the appropriate .rc file associated with your shell. If you are using bash then modify the .bashrc in your home directory. If you are using tcsh then you will modify your .tcshrc file. Add that export command to either file and it will automatically get set when you log in.

    Edit: I think you have to use the setenv command instead of export. So your command should look like

    setenv CLASSPATH .:$CLASSPATH
     
  7. Moderator emeritus

    Joined:
    Jun 25, 2002
    Location:
    Gone but not forgotten.
    #7
    It's not surprising. There was also an issue when they revised to 1.4 and they eventually got a developer tools update together which took care of the problem. If you look at downloads for tools on the Apple developer site, you'll find the update in 2003.

    Hopefully, they'll be swift about it.
     
  8. thread starter macrumors regular

    Joined:
    Dec 24, 2002
    Location:
    Chicagoland
    #8
    When I was running 10.2, it was already set and all I needed was the "java" and "javac" commands. If they did it before, I'd expect Panther to have it set up as well.
     

Share This Page