Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing from textarea to file followup question

Status
Not open for further replies.

jeremytaffy

Technical User
Sep 6, 2001
75
US
I tried the following lines of code to print the information from text field to a file at the press of a button called "start":

start.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
FileOutputStream file =
new FileOutputStream("/home/smash/test");
ObjectOutputStream out =
new ObjectOutputStream(file);
out.WriteObject(row1);
} catch (java.io.IOException e) {
System.out.println("Cannot access file");
}
}
});
//row1 is the panel name to which the jtextfield is added.

I keep getting the error that e is already defined in actionPerformed(java.awt.event.ActionEvent) ....

Please let me know how to fix this problem or any more appropriate ways of getting this to work.

Thanks in advance.
 
The reason you're getting this compiler error is because the name of the ActionEvent parameter you're passing in is "e", and then in the catch block where you're catching the IOException, you're attempting to assign the same name of "e" to the exception.

To prevent this problem, rename one of the "e" variables to something else. In general, it's a better idea to err on the side of more descriptive variable names.

Best,
Adam Rice
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top