Jump to content
Sign in to follow this  
madsovenielsen

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

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...