• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NoSuchMethodError

 
Jing Liang
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have received Exception in thread "main" java.lang.NoSuchMethodError: FamilyTree.grandchildren when runing my code.

In my FamilyTree.class, I did write a grandchildren() method, I don't understand why is it saying no such method.

In order to run the FamilyTree.class, just compiled the FamilyTree.java and download Record, Person.class, Main.class and Birthday.class from
http://www.ecst.csuchico.edu/~jhliang/csci111/lab6/lab6.html

In the console type in java Main restore

Please help me out? Thanks

 
Joe Ess
Bartender
Posts: 9320
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When was the last time you compiled FamilyTree? Chances are you have an old .class file in your classpath that does not have the grandchild method in it.
 
Jing Liang
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did save my file every time that I made a change. So I am pretty sure it was updated.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You saved the .java file, the source file. However it's possible that the .class file did not get updated. Depending on how you're compiling, this can happen easily when using Java. Unfortunately. I recommend you look for a file named FamilyTree.class, and look at its timestamp. Compare it to FamilyTree.java. Is it newer, or older? Should be newer, but if it's older, you've found the problem. Now even if it's newer - is it possible that somewhere on your system you've got another FamilyTree.class file, an old one that you've forgotten about?

Check your class path to see all the places the JVM could be looking for class files. I recommend you don't even use the CLASSPATH system variable; instead just use the java -cp option to specify the classpath when you compile. Don't let the classpath accumulate a bunch of stuff - keep it short, limited to places that have code that you actually need for the current program. That will make it less likely in the fiture that you might have old, forgotten class files lying around someplace that will cause problems.
 
gopinathang nathan
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try adding System.out.println() line to java file, save,compile, run and check whether you are able to see the newly added SOP statements.
 
Jing Liang
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sure it is the right class file. I checked the properties of the FamilyTree.class file, it's modified and accessed times were current.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15495
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have another copy of the file FamilyTree.class somewhere in another directory that's also in your CLASSPATH, or do you maybe have a JAR file in your CLASSPATH that contains an old version of FamilyTree.class?

To be extra sure, carefully check your CLASSPATH, delete all *.class files and recompile everything.

This is really the only possible cause for the error you get - so check and check again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic