 |
 |
Problem in using MRJFileUtils.openURL()
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: May 2001
Location: India
Status:
Offline
|
|
hi,
i m using the following code snippet for launching the default browser
with a given URL (say www.google.com).
try
{
MRJFileUtils.openURL(url);
}
catch (IOException ex)
{
ex.printStackTrace();
}
but its giving the following error:
MRJFileUtils.findApplication is unimplemented yet.
what is this error? what could be the solution?
I m using MRJ 3.0 on Mac OS X.
Please help. Its urgent.
thanx and regards.
Rachna
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Nov 2000
Status:
Offline
|
|
The MRJxxx stuff is a hold-over from OS9's MacOS Runtime for Java.
"MRJFileUtils.findApplication is unimplemented yet." is exactly what it says. The method MRJFileUtils.findApplication() is empty and this gets called on to find the browser by MRJFileUtils.openURL() so it can launch it.
At this point you should look at NSWorkspace to open URLs. All the MRJxxx stuff is platform specific so using NSWorkspace should be ok. My guess is Apple will eventually map the MRJxxxx stuff to the Cocoa bridged stuff or it may just disappear - who knows.
Look at com.apple.cocoa.NSWorkspace. The easiest way to find it is through (/Developer/Applications/)Java Browser.
Good luck! 
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: May 2001
Location: India
Status:
Offline
|
|
ok...thanx for the reply.
But now as i m using NSWorkspace openURL(url) method to launch the url in the default browser, i get NoClassDefFoundError().
my code:
import com.apple.cocoa.application.*;
import java.net.*;
public class OpenFile
{
NSWorkSpace itsWSpace = new NSWorkSpace();
URL itsURL = null;
public OpenFile()
{
try
{
itsURL = new URL("www.google.com");
}catch(MalformedURLException e)
{
e.printStackTrace();
}
boolean result = itsWSpace.openURL(itsURL);
}
public static void main(String args[])
{
OpenFile aFile = new OpenFile();
}
}
while i have added all the framworks.
what should i do ?
Please help. Its Urgent.
thanx n regards.
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Apr 2001
Location: San Francisco, USA
Status:
Offline
|
|
First of all, NSWorkspace is a singleton and you shouldn't be creating one with "new". Use NSWorkspace.sharedWorkspace() to get your application's NSWorkspace object. Second, www.google.com has no protocol specified, so it is not a valid URL. You should use something like http://www.google.com/ . HTH
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Apr 2001
Location: San Francisco, USA
Status:
Offline
|
|
Ah. Most importantly, the class is named NSWorkspace, not NSWorkSpace. The second 's' is not capitalized.
Edit: spelling clarification
[ 06-04-2001: Message edited by: honeydew ]
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: May 2001
Location: India
Status:
Offline
|
|
ok..
now i have changed it to NSWorkspace.sharedWorkspace(),
but the problem is still the same.
i.e. i m still getting NoClassDefFoundError().
now what to do?
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Apr 2001
Location: San Francisco, USA
Status:
Offline
|
|
The following code compiles and runs fine on my machine. If you are using the command line instead of Project Builder, make sure you are specifying your classpath correctly.
% javac -classpath /System/Library/Java:. OpenFile.java
% java -classpath /System/Library/Java:. OpenFile
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>import com.apple.cocoa.application.*;
import java.net.*;
<font color = green>public</font> class OpenFile
{
NSWorkspace itsWSpace = NSWorkspace.sharedWorkspace();
URL itsURL = null;
<font color = green>public</font> OpenFile()
{
try
{
itsURL = new URL(<font color = red>"http:<font color = brown>//www.google.com/"</font>);</font>
}catch(MalformedURLException e)
{
e.printStackTrace();
}
<font color = green>boolean</font> result = itsWSpace.openURL(itsURL);
}
<font color = green>public</font> <font color = green>static</font> <font color = green>void</font> main(String args[])
{
OpenFile aFile = new OpenFile();
}
}</font>[/code]
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: May 2001
Location: India
Status:
Offline
|
|
I am using Project Builder for development.
My platform is iMac with Mac OS X and MRJ3.0.
Can u pls tell me what frameworks and additional files(if any ) u r adding to ur project ?
and also if u r doing some additional classpath settings.
thanx.
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Apr 2001
Location: San Francisco, USA
Status:
Offline
|
|
Well, step one is to compile. You are using standard Java and Cocoa classes, so Project Builder should have no problems. I created a new "Java Application" project in PB, added the OpenFile.java file and successfully compiled with no further modifications.
Step two is running the app. You want OpenFile.main() to be executed when your app launches, correct? And you also need the Cocoa classes in your classpath. Find the MRJApp.properties file in your project and make sure everything is set up properly. The first two lines should look like
com.apple.mrj.application.main = OpenFile
com.apple.mrj.application.classpath = Contents/Resources/Java/<YourAppName>.jar:/System/Library/Java
This works for me. Good luck.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: May 2001
Location: India
Status:
Offline
|
|
thanx very much for the replies.
my problem has been solved at last
actually the problem was due to path.
as i set the correct classpath,
com.apple.mrj.application.main = OpenFile
com.apple.mrj.application.classpath = Contents/Resources/Java/<YourAppName>.jar:/System/Library/Java
the problem was solved.
thanx again
Rachna
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|