• Menu
  • Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

JavaBeat

Java Tutorial Blog

  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)

java.lang.NoSuchMethodError

March 15, 2014 //  by Krishna Srinivasan//  Leave a Comment

NoSuchMethodError is thrown when a Java class trying to invoke a method from another class which is not exist. Typically, this error has to be caught at the compile time. However, this error also thrown at run time when class has incompatibly changed. This error is sub class of java.lang.IncompatibleClassChangeError. This class inherited from the LinkageError super class.

Look at the below class without main method:

package javabeat.net.util;
public class HelloError {
	//No Main method
	public void method(){

	}
}

When you run the above program, you would get the below exception:

Exception in thread "main" java.lang.NoClassDefFoundError: HelloError (wrong nam
e: javabeat/net/util/HelloError)
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$100(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)

The requirement for the main method is :

  • The method must be exist in the class.
  • The name of the method must be exactly “main”.
  • The method must be public.
  • The method must be static.
  • The method’s return type must be void.
  • The method must have exactly one argument, and the type of that argument must be String[].

But, in the real scenarios the error will be thrown for the many other situations not just for the main method. When you have the wrong JAR files which don’t have the correct version of the method which you are invoking.

Category: JavaTag: Core Java, Java Exceptions, Java Lang

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Previous Post: « Spring Data Couchbase 1.0 GA Released!!
Next Post: java.lang.ArrayIndexOutOfBoundsException »

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow Us

  • Facebook
  • Pinterest

FEATURED TUTORIALS

New Features in Spring Boot 1.4

Difference Between @RequestParam and @PathVariable in Spring MVC

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Introductiion to Jakarta Struts

What’s new in Struts 2.0? – Struts 2.0 Framework

JavaBeat

Copyright © by JavaBeat · All rights reserved
Privacy Policy | Contact