java - I am trying to create a file via a button press but i keep running into an error -
i creating checkbook , unable create file write each separate account. when try create file error "unreported exception ioexception; must caught or declared thrown". try declare action listener method throws exception makes action listener method no longer able work. tried create separate method creates file , called button press still run same error
here code:
public void actionperformed(actionevent e) { ... if (e.getsource() == create) { creatnewaccount(name3.gettext()); balance = double.parsedouble(name2.gettext()); } } public void creatnewaccount(string s) throws ioexception { filewriter fw = new filewriter(s + ".txt", false); }
creatnewaccount
declared possibly throwing ioexception
. ioexception
not runtimeexception
, must catch it.
if (e.getsource() == create) { try { creatnewaccount(name3.gettext()); } catch (ioexception ie) { ie.printstacktrace(); // handle error } balance = double.parsedouble(name2.gettext()); }
for more information, please read the catch or specify requirement , catching , handling exceptions.
a few other things noticed: - word you're looking create, not creat. - you're assigning balance
. uppercase names reserved constants. consider renaming variable balance
. - consider more descriptive names text fields. name2
, name3
don't much.
Comments
Post a Comment