Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6161307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:27:24+00:00 2026-05-23T21:27:24+00:00

Introduction: There are many questions as How to fix java.lang.NoSuchMethodError on SO. As I

  • 0

Introduction:

There are many questions as How to fix java.lang.NoSuchMethodError on SO.

As I can see, the simplest way to get this error, is to make a class

class MyClass {} // no methods at all, for instance

without properly defined main method,
compile it and run:

java MyClass

Exception emerges:

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

But this example is too simple.

The question:

Could anyone provide a simple code, which

  1. Consists of two, maximum three classes (if you can show that more classes are needed – then you are welcome);
  2. Contains properly defined main method;
  3. Running of the class with that main method, leads to exception with java.lang.NoSuchMethodError.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T21:27:25+00:00Added an answer on May 23, 2026 at 9:27 pm

    NoSuchMethodError happens if one class expects a method in another class (and was compiled with that method in place), but at runtime the other class does not have that method. So you need to:

    • create two classes, one of which calls a method on the other
    • compile the two classes
    • then remove the invoked method from the 2nd class, and compile the 2nd class only

    Then, if you run the first class (with main method), it will throw that error when trying to call the method on the 2nd class (the method no longer exists)

    This example would rarely happen in the real world though. Here are some real cases when the error occurs:

    • You are using a 3rd party library (jar) that depends on another jar. However you are having incompatible versions of those jars, and the 1st one tries to invoke a method on a class in the 2nd
      jar that does not exist anymore/yet.
    • Your compile-time and runtime classpaths differ – you have compiled your code against a version of some library (that can also be the JDK itself), but your runtime is having other versions
    • You have a multi-module project. Your IDE “links” the project at compile-time, so any changes is seen immediately. But when you build you forget to compile one of the modules (where you have added a method), so at runtime it is using the old version.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using PHP, is there a nice way to get the (parsed) introduction only from
How can I count how many previous FootNoteReference nodes there are in an xml
Is there any way to have kind of Jyjamas(Java thing!!) where python has something
Introduction: I asked this question on the P2-forum already but I couldnt get any
How exactly does NSInvocation work? Is there a good introduction? I’m specifically having issues
Introduction I've always been searching for a way to make Visual Studio draw a
Introduction In my current organisation, we have many desktop and web applications all feeding
Introduction: Now I know this question could be very broad and it would be
INTRODUCTION I'm using excel downloads as a way of users downloading a score sheet,
Introduction: I'm trying to get additional fields to log with log4j, and its working

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.