Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 6, 2009, 02:20 AM   #1
Omega Duck
macrumors newbie
 
Join Date: Jan 2009
IOExceptions

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
Omega Duck is offline   0 Reply With Quote
Old Feb 6, 2009, 07:17 AM   #2
foidulus
macrumors 6502a
 
Join Date: Jan 2007
Quote:
Originally Posted by Omega Duck View Post
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.
foidulus is offline   0 Reply With Quote
Old Feb 6, 2009, 10:49 AM   #3
Krevnik
macrumors 68020
 
Krevnik's Avatar
 
Join Date: Sep 2003
Quote:
Originally Posted by Omega Duck View Post
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.
__________________
iMac 2013 27", 13" rMBP, iPad 4, iPhone 5s
Krevnik is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Forum Jump

All times are GMT -5. The time now is 12:40 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC