Jump to content


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


4 replies to this topic

#1 madsovenielsen

    Member

  • Members
  • PipPip
  • 141 posts
  • Gender:Male
  • Location:Denmark
  • Languages:XHTML, CSS, JavaScript, XML, ASP, PHP,

Posted 02 October 2010 - 12:27 PM

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

#2 aspnetguy

    Web Developer

  • Members
  • PipPipPipPipPipPip
  • 6,770 posts
  • Gender:Male
  • Location:Canada
  • Languages:PHP, ASP.NET, C#, JavaScript, HTML, CSS

Posted 04 October 2010 - 06:58 PM

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.
justin » My Blog | church attendance software | order of wedding speeches

please...
» ...do a search before asking a question, it has probably already been answered
» ...read the tutorials, chances are they also have the answer to your question
» ...be specific when describing your problem and if possible provide your code and/or a link

#3 sansana

    Member

  • Members
  • PipPip
  • 280 posts
  • Gender:Male
  • Location:Trinidad & Tobago
  • Interests:Information Systems, Web Technologies, Operating Systems, Nature, Photography, Thinking
  • Languages:PHP, Java, JavaScript, HTML, CSS

Posted 12 October 2010 - 11:54 PM

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.

#4 vipul_vj

    Newbie

  • Members
  • Pip
  • 40 posts
  • Gender:Male
  • Location:delhi
  • Languages:HTML,CSS,javascript,drupal,learning php,java

Posted 06 July 2011 - 03:21 PM


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 Hello
C:\java>Exception in thread "main" java.lang.NoClassDefFoundError:Hello

It 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=CLASSPATH

Value=.;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, 06 July 2011 - 03:23 PM.

Quote

Visit my website http://programmingbulls.com and find answers to all your problems on

web-designing,programming languages and other related problems.

#5 smiles

    Ancient Cipher

  • Members
  • PipPipPip
  • 773 posts
  • Gender:Male
  • Location:VietNam

Posted 15 December 2011 - 03:43 PM

You forgot constructor function in fileOps.java :)
Going is Coming >> My αsite > Xin chào các bạn !!!

CÁC BẠN VIỆT NAM ĐÂU HẾT RỒI VẬY ???





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users