1

I am writing a program that has 3 specific classes, ImageHandler, TiffHandler, and JPEGHandler.

JPEGHandler and TiffHandler both extend ImageHandler. Inside of all 3 classes is a method called compress() which compresses whatever image the object is currently handling.

I am also trying to create a separate class that implements Runnable, but I don't want to have to create two Runnable classes, one for TiffHandler and one for JPEGHandler. I would rather just create a Runnable class that can accept a ImageHandler object.

My issue is that since the Runnable class only has an ImageHandler object, whenever I call compress() it throws errors during runtime saying that:

Uncompilable source code - compress() in fjimagecompressor.JPEGHandler cannot override compress() in fjimagecompressor.ImageHandler
  overridden method does not throw java.io.IOException

The second line confuses me, as inside of ImageHandler I have a blank method called compress():

    public void compress() throws IOException{    
        /*blank*/
    }

and inside of TiffHandler and JPEGHandler I also have compress() which throws IOException, except compress() does something different depending on if it is a JPEGHandler or a TiffHandler. I am unsure whether I am simply using polymorphism incorrectly or if I am missing something in my super class ImageHandler. Why is the compiler saying that the super method doesn't throw an IOException when I do indeed declare that it does?

4
  • 4
    You should post the code for your *Handler classes, but the problem is that the copy of ImageHandler that the runtime sees doesn't have the throws clause. Clean and recompile. Commented Oct 21, 2013 at 5:50
  • 1
    Wow...I cleaned and rebuilt and it worked. Thats all I had to do? Now I feel silly -.-. Thanks! Commented Oct 21, 2013 at 5:53
  • 1
    If you're not using an IDE, give one a try. Eclipse in particular can keep this sort of error from happening with its incremental compilation feature. Commented Oct 21, 2013 at 5:56
  • its wrong thing... why u just posting things withought any efforts?? its not the standard way... should first try all the things den you need to ask the question Commented Oct 21, 2013 at 5:57

1 Answer 1

2

The issue is probably that your .class file and your .java file are out of sync, and while you can compile because you added the throws clause to ImageHander.java, you didn't get the compiled code updated. Clean and recompile your whole project and the error should go away.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.