Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Omega Duck

macrumors newbie
Original poster
Jan 30, 2009
4
0
hi,
I am pretty new to Java and i have been trying to launch an application from the code, as in the user presses a JButton or something and the application opens.

But now I have a problem, i have an "unreported exception java.io.IOException;"

Now I am not sure what to do, I tried to catch it, but i dont know how, and and then i tried to throw it and that did work either.

if (event.getSource() == nItem) {

String command="/usr/bin/open/Applications/Firefox.app";
Process child = Runtime.getRuntime().exec(command);
}

This is the code, I dont know what to do, as in how and where to throw or to catch.

Thanks a lot
 

foidulus

macrumors 6502a
Jan 15, 2007
904
1
hi,
I am pretty new to Java and i have been trying to launch an application from the code, as in the user presses a JButton or something and the application opens.

But now I have a problem, i have an "unreported exception java.io.IOException;"

Now I am not sure what to do, I tried to catch it, but i dont know how, and and then i tried to throw it and that did work either.

if (event.getSource() == nItem) {

String command="/usr/bin/open/Applications/Firefox.app";
Process child = Runtime.getRuntime().exec(command);
}

This is the code, I dont know what to do, as in how and where to throw or to catch.

Thanks a lot

First, you need a space between open and /Applications

Second, you can get more information by running the console app and looking at the trace. /Applications/Utilities/Console.app

Finally, and most importantly, you should put the whole thing in a try/catch block regardless of whether or not your code is correct because bad things can and do happen. I won't go into the nuances of exception handling here, but add the following code to your app and run it from the command line or look at the console again

(after the if)
try {
String command="/usr/bin/open/Applications/Firefox.app";
Process child = Runtime.getRuntime().exec(command);
}
catch(Exception e) {e.printStackTrace();}

} //If statement's bracket.

That will tell you what line problem is happening on as well as give you some other useful trace. While catching Exception is a but brute force, for now it will at least get you acclimated to basic exception handling.
 

Krevnik

macrumors 601
Sep 8, 2003
4,100
1,309
hi,
IBut now I have a problem, i have an "unreported exception java.io.IOException;"

Now I am not sure what to do, I tried to catch it, but i dont know how, and and then i tried to throw it and that did work either.

Are you sure you didn't read that as "uncaught exception"? Granted my Java is rusty, but that seems like a really worthless error message if it actually told you 'unreported'.

But what is happening (in this case) is that 'unreported exception' means that someone threw an exception, and the Java runtime had to catch it because you didn't.

Follow the steps the other poster gave you, as they are spot on in this case for someone who is still learning.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.