Jump to content

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


madsovenielsen
 Share

Recommended Posts

HelloI 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 applicationfileOps.java

/* * 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

/* * 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

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

Netbeans! I belive you need to declare 'import backup.fileOps;' to use that class and make sure even thought they are in the same package they are also in the same package folder.

Link to comment
Share on other sites

  • 8 months later...

Java compiler(javac) converts *.java file into *.class file.Now this byte code is converted into machine code by the JVM.Classpath variable is used by the JVM to search *.class files in different directories.C:\java> java HelloC:\java>Exception in thread "main" java.lang.NoClassDefFoundError:HelloIt means that JVM was not able to find *.class file or simply the byte code.Even after setting the PATH Variable and CLASSPATH variable correctly this error occurs.Do you know where the problem is?It lies in the CLASSPATH Variable.In the CLASSPATH there should be .;set the classpath in enviorment variable in the following manner:name=CLASSPATHValue=.;c:\programme\jboss\lib;c:\programme\j2sdk1.4.2_08\lib;c:\programme\j2sdk1.4.2_08\jre\lib; ...yes.. a dot .. it means, that JVM will search for classes bytecode in the current directory !!

Edited by vipul_vj
Link to comment
Share on other sites

  • 5 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...