• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

serialiazation- run time exceptions

 
Mohd Abrar Khan
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21419
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Compiles and runs with no exceptions for me...

Henry
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21419
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Delete your class files. Delete your .ser file. Recompile everything. And try again.

Henry
 
Mohd Abrar Khan
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remember that although serialization is very interesting and useful it's not the the exam for SCJP 6.
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Saloon Keeper
Posts: 15441
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic