• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NoSuchMethodError

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic