Go Back   Velocity Reviews > Newsgroups > Java
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

Java - Back and Forth between Two Kinds of Error Messages

 
Thread Tools Search this Thread
Old 08-03-2006, 01:09 AM   #1
Default Back and Forth between Two Kinds of Error Messages


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
  Reply With Quote
Old 08-03-2006, 01:21 AM   #2
kvnsmnsn@hotmail.com
 
Posts: n/a
Default Re: Back and Forth between Two Kinds of Error Messages
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_



kvnsmnsn@hotmail.com
  Reply With Quote
Old 08-03-2006, 01:27 AM   #3
jmcgill
 
Posts: n/a
Default Re: Back and Forth between Two Kinds of Error Messages
wrote:

> 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).


jmcgill
  Reply With Quote
Old 08-03-2006, 04:59 AM   #4
kvnsmnsn@hotmail.com
 
Posts: n/a
Default Re: Back and Forth between Two Kinds of Error Messages
jmcgill wrote:

=> 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_



kvnsmnsn@hotmail.com
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46