Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2006

Tip: Looking for answers? Try searching our database.

Back and Forth between Two Kinds of Error Messages

Thread view: 
kvnsmnsn@hotmail.com - 03 Aug 2006 01:09 GMT
I've got a file "DefaultIntValue.java" that implements interface
<IIntValue> which is a descendant of <IValue> which requires it to
have <writeObject()> and <readObject()> methods, and four other files
that do similar things except that instead of reading and writing
<int>s they read and write <double>s, <float>s, <long>s and <String>s.

I originally defined the "DefaultIntValue.java" methods like so:

 public void writeObject ( ObjectOutputStream isOut)
 {
   isOut.writeInt( integer);
 }

 public void readObject ( ObjectInputStream isIn)
 {
   integer = isIn.readInt();
 }

But when I compiled these "DefaultIntValue.java" methods the compiler
told me "Unhandled exception type IOException" for both methods, and
got identical complaints for each of the other four files.

So I went in and changed my methods like so:

 public void writeObject ( ObjectOutputStream isOut)
                         throws IOException
 {
   isOut.writeInt( integer);
 }

 public void readObject ( ObjectInputStream isIn)
                        throws IOException
 {
   integer = isIn.readInt();
 }

and did similar changes to each of the four other files and then com-
piled, and the message the compiler gave me was, "Exception
IOException is not compatible with throws clause in
IValue.writeObject(ObjectOutputStream)" for <writeObject()> and "Ex-
ception IOException is not compatible with throws clause in
IValue.readObject(ObjectInputStream)" for <readObject()>.  I got simi-
lar errors for each of the four other files.

Can anyone tell me what these compilation errors mean and what I have
to do to get these files to compile?  Any feedback would be greatly
appreciated.

                               ---Kevin Simonson

"You'll never get to heaven, or even to LA,
if you don't believe there's a way."
from _Why Not_
kvnsmnsn@hotmail.com - 03 Aug 2006 01:21 GMT
If it makes a difference all of this was done using Eclipse.

                               ---Kevin Simonson

"You'll never get to heaven, or even to LA,
if you don't believe there's a way."
from _Why Not_
jmcgill - 03 Aug 2006 01:27 GMT
> and did similar changes to each of the four other files and then com-
> piled, and the message the compiler gave me was, "Exception
> IOException is not compatible with throws clause in
> IValue.writeObject(ObjectOutputStream)"

You cannot simply add a throws clause to a method that overrides a
method in a superclass.

You need to either put a try block around your call and actually handle
the error, or else you need to add the throws clause to the superclass(es).
kvnsmnsn@hotmail.com - 03 Aug 2006 04:59 GMT
=> and did similar changes to each of the four other files and then
com-
=> piled, and the message the compiler gave me was, "Exception
=> IOException is not compatible with throws clause in
=> IValue.writeObject(ObjectOutputStream)"
=
=You cannot simply add a throws clause to a method that overrides a
=method in a superclass.
=
=You need to either put a try block around your call and actually
=handle the error, or else you need to add the throws clause to the
=superclass(es).

Now I _really_ feel stupid.  I'm sure this will fix my problem.

                               ---Kevin Simonson

"You'll never get to heaven, or even to LA,
if you don't believe there's a way."
from _Why Not_


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.