Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 26th, 2005, 3:46 PM   #1
elford
Programmer
 
elford's Avatar
 
Join Date: Nov 2005
Posts: 35
Rep Power: 0 elford is on a distinguished road
Exception troubles dealing with GUIs

I've written an application that runs fine from a console, so I am now building a GUI on top of it.

When the user clicks on the "Run" button I provide, the GUI takes 3 strings (paths and file names) the user inputted and passes them off to the rest of the program. The methods that handle the files can throw FileNotFound and IO Exceptions.

Here is the method that passes control from the GUI to the rest of the program:
private void runWidgetSelected(SelectionEvent evt) throws IOException {
	try{
		BandTrack.runFromGUI(rosterLoc.getText(), swipeLoc.getText(),
			exportLoc.getText());
		}
		catch (IOException e){
			e.printStackTrace();
		}
	}

The problem that I am having is with the Listener that checks to see if the Run button has been selected:
run = new Button(this, SWT.PUSH | SWT.CENTER);
run.setText("Run!");
run.setBounds(280, 147, 63, 21);
run.addSelectionListener(new SelectionAdapter() {
	public void widgetSelected(SelectionEvent evt) throws IOException {
		runWidgetSelected(evt);
	}
});

Eclipse has that block underlined with the message "Exception IOException is not compatible with throws clause in SelectionAdapter.widgetSelected
(SelectionEvent)."

What does that mean? What is the way that it should be fixed?
elford is offline   Reply With Quote
Old Dec 26th, 2005, 4:21 PM   #2
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 855
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
You're method is throwing an exception that isn't an IOException. Replace all instances of IOException with Exception.
titaniumdecoy is offline   Reply With Quote
Old Dec 26th, 2005, 5:44 PM   #3
elford
Programmer
 
elford's Avatar
 
Join Date: Nov 2005
Posts: 35
Rep Power: 0 elford is on a distinguished road
Actually, I tried that before posting. The problem remains the same, except with the Eclipse error reading "Exception Exception is not compatible with throws clause in SelectionAdapter.widgetSelected (SelectionEvent)." instead.
elford is offline   Reply With Quote
Old Dec 26th, 2005, 6:38 PM   #4
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 855
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
Try changing catch(IOException e) to catch(Exception e) and removing "throws IOException" from both methods.
titaniumdecoy is offline   Reply With Quote
Old Dec 26th, 2005, 8:30 PM   #5
elford
Programmer
 
elford's Avatar
 
Join Date: Nov 2005
Posts: 35
Rep Power: 0 elford is on a distinguished road
It was the "throws" clause that it was choaking on. I caught the exception and didn't need to throw it again. I removed the throws clause from the method and all was well.
elford is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:20 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC