Results 1 to 6 of 6
- 12-01-2009, 02:59 PM #1
Member
- Join Date
- Apr 2009
- Posts
- 26
- Rep Power
- 0
Calling on class with throws IOException
Hi,
I have created a form and when the user clicks a button i would like it to call on a method in my connection class.
private void connectActionPerformed(ActionEvent evt) {
Connect connection = new Connect();
connection.startConnection(); //gives error -
unreported exception java.io.lang.IOException; must be caught or declared to be thrown
}
my connection class method is:
public void startConnection() throws IOException {
BufferedReader inFromUser = new BufferedReader(newInputStreamReader(System.in)) ;
//omited//
i think it has something to do with the throws IOException at the end of my startconnection method.
any help would be appreciated. many thanks
gisler
-
What happens if you follow the compiler's recommendation of placing the method call in a try/catch block?
If this doesn't make sense, please have a look here: Exceptions Tutorial
Much luck!
- 12-01-2009, 03:22 PM #3
Member
- Join Date
- Apr 2009
- Posts
- 26
- Rep Power
- 0
Cool thanks. that fixed it. It now looks like this:
private void connectActionPerformed(ActionEvent evt) {
try{
Connect connection = new Connect();
connection.startConnection();
}
catch (IOException e){
}
}
I do not understand why this is needed in this code since i only calling upon the method. what would there be here for me to catch?
thanks
gisler
-
Your code is no good as your catch block is empty, meaning if an exception occurs (can't start the connection, etc...) you're just ignoring this information and throwing it away. Please read the tutorial that I've linked to above as it will explain all. Also, please use code tags when posting code (see my signature for details).
Much luck.
- 12-01-2009, 03:46 PM #5
Member
- Join Date
- Apr 2009
- Posts
- 26
- Rep Power
- 0
ok, i will do that. thanks for the help
-
Similar Threads
-
change throws IOException
By manhtungtnk28@gmail.com in forum New To JavaReplies: 7Last Post: 11-23-2009, 08:39 AM -
Recursive Class throws NullPointerException
By freeBatjko in forum New To JavaReplies: 5Last Post: 11-03-2009, 09:18 AM -
Child-Class Calling a Method in a Parent-Class
By Blah_ in forum New To JavaReplies: 5Last Post: 09-29-2009, 02:48 AM -
problem calling function from class to class
By alin_ms in forum New To JavaReplies: 3Last Post: 12-19-2008, 07:35 PM -
Calling a method on original class from created class
By kpedersen in forum Advanced JavaReplies: 4Last Post: 08-20-2008, 12:25 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks