Quick Java question

LeetestUnleet

Senior member
Aug 16, 2002
680
0
0
First, it's not really my program, a friend of mine is having troubles and he asked me for help, but my solution isn't working. Basically, he just wants to execute different programs/scripts from one java program. He's running linux. We tried this:

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
Runtime.getRuntime().exec("/usr/local/bin/ballsmacker");
}

But it gives this error:

funnny.java [119:1] unreported exception java.io.IOException; must be caught or declared to be thrown
Runtime.getRuntime().exec("/usr/local/bin/ballsmacker");
 

agnitrate

Diamond Member
Jul 2, 2001
3,761
1
0
you have to put it in a try block and catch an Exception in case it cannot find the file you try and run or any other various errors that might pop up.

-silver
 

LeetestUnleet

Senior member
Aug 16, 2002
680
0
0
Ah, we've got it figured out now.

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {

try{
Runtime.getRuntime().exec("/usr/local/bin/ballsmacker");
}catch (IOException e) {
System.err.println("Caught IOException: " + e.getMessage());
}
}

Thanks for the tip-off!