Using JDIC to open web browser
Hi, I am trying to figure out JDIC (0.9.1), and how to use it to open an htm file in Internet Explorer.
My issue is that when I compile, it always says that It can't reference non-static method open(Java.io.File) from static context.
Its definitely NOT in a static context.
publicvoid myMethod(){
File testFile =new File("Index.htm");
Desktop.open(testFile);
}
I get the error on Desktop.open
To install it, I pretty much just copied jdic.jar, packager.jar, WinMsiWrapper.dll, and IeEmbed to java's working directory.
Anyone knoe what the issue is? Thanks
> Hi, I am trying to figure out JDIC (0.9.1), and how
> to use it to open an htm file in Internet Explorer.
> My issue is that when I compile, it always says that
> It can't reference non-static method
> open(Java.io.File) from static context.
>
> Its definitely NOT in a static context.
> > public void myMethod(){
>
>File testFile = new File("Index.htm");
> Desktop.open(testFile);
> }
>
>
That definitely IS a static context.
When you see the following.
ClassName.methodOrProperty
That is a static context because you are invoking a method or accessing a property of the class. Not an instance (object) of the class.
Note the difference between that and this
instanceName.methodOrProperty
So you need a reference to a Desktop instance.
huh, I did not know that. def. feel kinda stupid....Thanks
> huh, I did not know that. def. feel kinda stupid....It's okay, asking questions is how you learn. :)
Haha, yeah, I guess I just hate the learning curve...
Ok, one last thing, to verify, this code gives a reference to the Desktop instance, correct?
Desktop desktop = new Desktop();
?
This particular code tells me that Java.awt.Desktop() has private access. Do I have to override it somehow? Thanks again
> Haha, yeah, I guess I just hate the learning
> curve...
>
> Ok, one last thing, to verify, this code gives a
> reference to the Desktop instance, correct?
>
> Desktop desktop = new Desktop();
>
> ?
>
> This particular code tells me that Java.awt.Desktop()
> has private access. Do I have to override it somehow?
> Thanks again
You have to call a method from the API that gives you a reference that you can actually call (so not private) . I don't know what that might be...
Hold on
> This particular code tells me that Java.awt.Desktop() has private access. Do I have
> to override it somehow?
The fact that it has private access makes sense if you stop and think about it - there is only one desktop, and you have to use that desktop. The programmer can't go making their own! (Well, they can - but it won't have the desired effect which is to interact with the real desktop with its real browser etc).
There's no overriding it! What you have to do is go to the API documentation (http://java.sun.com/javase/6/docs/api/java/awt/Desktop.html) and see if you can find a method using which you can get a Desktop.
Wait...That IS a static method.So you do need to call it in a static context.What was the exact error message? And am I looking at the right documentation?https://jdic.dev.java.net/nonav/documentation/javadoc/jdic/org/jdesktop/jdic/desktop/Desktop.html
> Wait...> > That IS a static method.no it isn'tDesktop.getDesktop().open(file);
> That IS a static method.> So you do need to call it in a static context.Ha! The OP (or their IDE) made the same mistake I did - and imported the wrong Desktop.
> What was the exact error message? And am I looking at> the right documentation?hmm. my previous comment was based off the guy above you's link.
to cottonyeah that's the right APII get Desktop() has private access in java.awt.Desktopand the first error message has disappearedAnd How the heck would I import the right Desktop then?Message was edited by: snoboarder
> to cotton
>
> yeah that's the right API
>
> I get Desktop() has private access in
> java.awt.Desktop
>
> and the first error message has disappeared
Holy **** I'm getting confused. (not your fault ).
As pbrockway said your IDE thinks you are using one Desktop but you are trying to use another.
But maybe you do actually want to use java.awt.Desktop and just scrap the JDIC...
> > And How the heck would I import the right Desktop> then?If you want to use java.awt.Desktop then you already did. It looks like it has the same methods and such as the other one.
aaannnnnddd we have a winner!!!I ended up ditching the JDICfinal code File testFile = new File("Index.htm");Desktop.getDesktop().open(testFile);
*wave hand*this is not the desktop you are looking for.