Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2010
    Posts
    12
    Rep Power
    0

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

    Hello

    I get this error when i try to run my little application:

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

    The compiler dont throw any errors. its only when i try to execute the application

    fileOps.java
    Java Code:
    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    
    package backup;
    
    /**
    *
    * @author admin
    */
    public class fileOps {
        public String greeting(String args)
        {
            return args;
        }
    }
    Main.java
    Java Code:
    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    
    package backup;
    
    /**
    *
    * @author admin
    */
    public class Main {
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            fileOps dispGreeting = new fileOps();
            dispGreeting.greeting("hello");
        }
    
    }
    Whats wrong and how do i fix this ?

    Best regards Mads

  2. #2
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    5

    Default

    hello, i have stored your classes in a folder bin\backage. now from the bin directory call

    java backup.Main

    and your class will start but will output nothing unless you change the last line in the main() method to

    System.out.println(dispGreeting.greeting("hello")) ;

  3. #3
    Join Date
    Oct 2010
    Posts
    12
    Rep Power
    0

    Default

    Thanks for the answer.

    I found out that the problem was i had not set my CLASSPATH environment variable.

    I followed this guide: Java Package Tutorial (English version)

    Under Windows:

    C:\>set CLASSPATH=.;C:\;

    its working now.

    NB. This approach only works until the next reboot. you have to set it permanent under advanced system settings. right click "Computer" and choose environment variables. add it there.

Similar Threads

  1. Replies: 5
    Last Post: 06-02-2010, 01:05 PM
  2. Replies: 3
    Last Post: 06-01-2010, 03:01 PM
  3. Replies: 5
    Last Post: 09-29-2009, 12:14 PM
  4. Replies: 1
    Last Post: 04-02-2009, 09:50 PM
  5. Replies: 6
    Last Post: 08-18-2008, 06:44 AM

Posting Permissions

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