Results 1 to 4 of 4

Thread: Java Problem

  1. #1

    Java Problem

    Ok, didn't know if this should go here or somewhere else... but I gots a problem thats happened twice now and I don't know what it is. I have the latest non beta Java SDK (j2sdk1.4.2_04) installed and I used to be able to compile things via batch scripts I made... they would be something like this:

    Code:
    @echo off
    path=C:\j2sdk1.4.2_04\bin
    javac *.java
    java Driver
    But now everytime I run these batch files that worked before, I get this error:

    Exception in thread "main" java.lang.NoClassDefFoundError: Main
    And to answer any obvious questions, my programs do have a main method and they have compiled perfectly before and do so on different systems as well.

    I've reinstalled Java three times and still haven't been able to get it work. The only way I am able to use Java at all is by installing the Netbeans IDE and using package statements in my code. This being the 2nd time this has happened since I started coding (fixed first time by formatting), I need some help?

    - dave t

  2. #2
    Well, the problem has been fixed by good ol' ZeroCool aka h3r3tic...

    Answer:

    # Fix the CLASSPATH variable if, when running the code, you see a message like this one:

    Exception in thread "main" java.lang.NoClassDefFoundError: MyHelloWorld

    To set the CLASSPATH variable:

    * Go to the Control Panel/System
    * Change to the "Advanced" tab
    * Click the button "Environment Variable" at the bottom of the dialog box
    * Select CLASSPATH and click Edit
    * Locate the "Variable Value" field. Add the following text at the end

    ;.

    The semicolon is a separator and the . tells the JVM to look for classes in your current directory.
    From: http://www.cs.wfu.edu/~pauca/csc111/instructions.html

  3. #3
    Ninja Code Monkey
    Join Date
    Nov 2001
    Location
    Washington State
    Posts
    1,027
    For anyone using this method I'd recommend looking into Ant.

    http://www.iseran.com/Java/ant/tutor..._tutorial.html

    http://ant.apache.org/
    "When I get a little money I buy books; and if any is left I buy food and clothes." - Erasmus
    "There is no programming language, no matter how structured, that will prevent programmers from writing bad programs." - L. Flon
    "Mischief my ass, you are an unethical moron." - chsh
    Blog of X

  4. #4
    Custom User
    Join Date
    Oct 2001
    Posts
    503
    That sounds like a much better method than I was going to suggest :P I was just going to suggest running with the -classpath switch as in:

    Code:
    java -classpath .\mydir myclass
    If you have any packages, you just add them after mydir separating each with a semicolon. But I would think that the above method suggested by Juridian is probably much easier/better.

    I'm in the middle of writing a java program that will handle the creation of batch files for you, I'm just struggling with the design on the gui at the moment. As soon as I get a working version I'll post it to code review.

    ac

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •