File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes NoSuchMethodError Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "NoSuchMethodError" Watch "NoSuchMethodError" New topic
Author

NoSuchMethodError

Jing Liang
Ranch Hand

Joined: Oct 23, 2006
Posts: 40
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

Joined: Oct 29, 2001
Posts: 8867
    
    8

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.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Jing Liang
Ranch Hand

Joined: Oct 23, 2006
Posts: 40
I did save my file every time that I made a change. So I am pretty sure it was updated.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
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.


"I'm not back." - Bill Harding, Twister
gopinathang nathan
Ranch Hand

Joined: Oct 28, 2006
Posts: 41
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

Joined: Oct 23, 2006
Posts: 40
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

Joined: Aug 16, 2005
Posts: 14111
    
  16

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: NoSuchMethodError