madsovenielsen Posted October 2, 2010 Share Posted October 2, 2010 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 Link to comment Share on other sites More sharing options...
aspnetguy Posted October 4, 2010 Share Posted October 4, 2010 Is there more to the error message? It should be telling which class it can't find.The NoClassDefFoundError is caused due to classpath problems or missing jar files. Link to comment Share on other sites More sharing options...
trinistorm Posted October 12, 2010 Share Posted October 12, 2010 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 More sharing options...
vipul20_j Posted July 6, 2011 Share Posted July 6, 2011 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 !! Link to comment Share on other sites More sharing options...
smiles Posted December 15, 2011 Share Posted December 15, 2011 You forgot constructor function in fileOps.java Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.