aspose file tools*
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
Author

NoSuchMethodException

Arun Maalik
Ranch Hand

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

catch(NoSuchMethodException e){
System.out.println(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
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: NoSuchMethodException