Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NoSuchMethodException

 
Arun Maalik
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Arun Maalik
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks sir
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic