wood burning stoves
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
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: 24199

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: http://aspose.com/file-tools
subject: NoSuchMethodException
jQuery in Action, 3rd edition