| Author |
serialiazation- run time exceptions
|
Mohd Abrar Khan
Greenhorn
Joined: Jan 20, 2010
Posts: 18
|
|
Hi when ever i am running any serialization based prgm i getting the followng error at run time, compilation is fine,
please advice where am i going wrong.
at run time i am getting the following error,
// Exception in thread "main" java.lang.NoSuchMethodError: Dog.<init>(ILjava/lang/String;)V
// at SuperNotSerial.main(SuperNotSerial.java:7)
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16695
|
|
Compiles and runs with no exceptions for me...
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Tim McGuire
Ranch Hand
Joined: Apr 30, 2003
Posts: 819
|
|
works fine for me too.
I could reproduce your error, though, if I compiled another class named Dog after compiling SuperNotSerial. The new Dog will replace the one SuperNotSerial is expecting. As the Error implies, the underlying Dog class somehow changed after you compiled SuperNotSerial. Any ideas on how this happened?
|
 |
Mohd Abrar Khan
Greenhorn
Joined: Jan 20, 2010
Posts: 18
|
|
Hi Guys
thanks for your time,
Tim, i have no idea how the Dog class is changing,
i have tried running the same programme in Netbeans IDE, its giving correct output there,
problem is comming while running through JVM,
i am still unable to sort out the exception.
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16695
|
|
Delete your class files. Delete your .ser file. Recompile everything. And try again.
Henry
|
 |
Mohd Abrar Khan
Greenhorn
Joined: Jan 20, 2010
Posts: 18
|
|
Henry thanks i have done that it was giving the same error,
now i have moved the file to a different location and ran it from there its working fine now,
just had a doubt say for eg: if i have another class file which contains a dog Subclass, i have executed this file and its ok,
and currently if i am running this programme which also has a dog class , so does this cause a problem in execution of my current programme
both the files are in same directory location,
|
 |
Wouter Oet
Saloon Keeper
Joined: Oct 25, 2008
Posts: 2700
|
|
|
Remember that although serialization is very interesting and useful it's not the the exam for SCJP 6.
|
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
|
 |
Tim McGuire
Ranch Hand
Joined: Apr 30, 2003
Posts: 819
|
|
Mohd Abrar Khan wrote:
i have another class file which contains a dog Subclass, i have executed this file and its ok,
and currently if i am running this programme which also has a dog class , so does this cause a problem in execution of my current programme
both the files are in same directory location,
Yes sir. This is what I was asking about. the other class file's Dog subclass will replace your other Dog.
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12929
|
|
A NoSuchMethodError indicates that you have an old class file somewhere in which the indicated method is missing (in your case, it's complaining about a missing constructor in class Dog that takes an int and a String). You have an old version of Dog.class that gets picked up.
Mohd Abrar Khan wrote:Henry thanks i have done that it was giving the same error,
now i have moved the file to a different location and ran it from there its working fine now,
You must have missed something, in the old location or somewhere in your classpath was probably still an old version of Dog.class.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
 |
|
|
subject: serialiazation- run time exceptions
|
|
|