This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes NoSuchMethodException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "NoSuchMethodException" Watch "NoSuchMethodException" New topic


Arun Maalik
Ranch Hand

Joined: Oct 25, 2005
Posts: 216
public class first{
public static void main(String[] args) throws NoSuchMethodException{
first p=new first();

catch(NoSuchMethodException e){

Dear sir in the above code it should throw NoSuchMethodException becouse showData() is not in class first that is on run time. But it is genrating a compile time error that can't resolve symbol why sir? and if it true then when does NoSuchMethodException is thrown?

with regard

Arun kumar maalik
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24183

NoSuchMethodError happens at runtime when the .class files don't match the source code that the compiler saw. Imagine two classes where code in one class A calls a method in a second class B. First, compile both classes, then modify B to remove that method and recompile only B. Now when you run A, you'll see this exception.

In your case, the compiler can see the method is missing already, so it refuses to even compile the code.

[Jess in Action][AskingGoodQuestions]
Arun Maalik
Ranch Hand

Joined: Oct 25, 2005
Posts: 216
Thanks sir
I agree. Here's the link:
subject: NoSuchMethodException
Similar Threads
throw Exception
Accessibility of default constructors
Related to Exceptions
Using try-catch for program logic.
dynamically calling class that takes param in constructor