exception
Good evening all,
I'm taking a java class and as one of the final assignments, we've got to
write a program that uses a gui with buttons. We've got to use a function
that adds records. I've got this being handled by a button but i'm getting
an error that I need a throws exception. As luck would have it, the
instructor never covered this aspect of Java but I did find an example on
google. The problem i'm having is understanding how to use it. Since my
button processes the code it seems like the exception handling needs to be
there. I don't know of another way to call the button other than using the
listener, that triggers the event when the button is pressed. At this
point, i'm stuck. Any insight about how to do this, is appreciated. This
is an introductory java class so.
The error message I get.
X?StudentAddWindow.java:92: exception java.io.IOException is never thrown
in body of corresponding try statement
private class addButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
try
{ String name;
} catch (IOException x)
{
FileWriter swriter = new FileWriter("c:\\studname.txt",true);
JOptionPane.showMessageDialog(null,"The file could not be written.");
//name = StudentTextField.getText();
FileWriter swriter = new FileWriter("c:\\studname.txt",true);
//FileWriter gwriter = new FileWriter("c:\\grades.txt",true);
PrintWriter outputFile2 = new PrintWriter(gwriter);
//PrintWriter outputFile= new PrintWriter(swriter);
outputFile.println(name);
//outputFile2.println("0,0,0");
outputFile.close();
//outputFile2.close();
StudentTextField.setText("");
}
Thanks
Art