![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Nov 2005
Posts: 35
Rep Power: 0
![]() |
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? |
|
|
|
|
|
#2 |
|
Expert Programmer
|
You're method is throwing an exception that isn't an IOException. Replace all instances of IOException with Exception.
|
|
|
|
|
|
#3 |
|
Programmer
Join Date: Nov 2005
Posts: 35
Rep Power: 0
![]() |
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.
|
|
|
|
|
|
#4 |
|
Expert Programmer
|
Try changing catch(IOException e) to catch(Exception e) and removing "throws IOException" from both methods.
|
|
|
|
|
|
#5 |
|
Programmer
Join Date: Nov 2005
Posts: 35
Rep Power: 0
![]() |
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.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|