IOExceptions

This is really really annoying. I'm designing a GUI interface for my program, and when I click a button I have an action listener for that button.

When the action listener fires, it calls an object method, that creates another object, that reads files. Consequently all my methods require me to throw the IOException but I can't seem to throw it in my action listener? Any help/ suggestions?

privateclass ProcessButtonListenerimplements ActionListener

{

publicvoid actionPerformed(ActionEvent e)

{

options.process();

}

}

keep in mind this code generates an error when I compile telling me that an unreported IOException should be caught or thrown. When i tack "throws IOException" onto the end of the method, it give me another compiler error I can't figure out.

actionPerformed(java.awt.event.ActionEvent) in guipod.ProcessButtonListener cannot implement actionPerformed(java.awt.event.ActionEvent) in java.awt.ActionListener; overridden method does notthrow java.io.IOException

[1355 byte] By [imdandmana] at [2007-11-27 6:12:03]
# 1

try

{

options.process();

}

catch(IOException e)

{

e.printStackTrace();

}

Tada!

CaptainMorgan08a at 2007-7-12 17:18:56 > top of Java-index,Java Essentials,Java Programming...
# 2

Okay. Bottom line is that you cannot throw an IOException in an

actionPerformed

Because when you implement a method of an interface you can ONLY

throw the exceptions that the method is declared to throw in the

interface.

So you will have to deal with the IOException from somewhere inside

your action listener.

But this is okay because this is a good place to deal with it. The action

which was triggered by a user event did not work. So you could do as

simple as throwing up a JOptIonPane with an error message telling the

user that it failed. Whatever you want to do.

cotton.ma at 2007-7-12 17:18:56 > top of Java-index,Java Essentials,Java Programming...