1

I have the following code

    desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
    url = new URL("http://www.facebook.com");
    if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
        try {
            desktop.browse(url.toURI());
        } catch (Exception e) {
            e.printStackTrace();
        }

and desktop is returning null for Windows 7. Can anyone suggest what to be done ?

Kesavacharan
  • 318
  • 3
  • 14

2 Answers2

1

Not sure it's not working with Windows 7 (it worked at me), but Desktop can return false negatives anyway. I had a similar problem and the only way around I could find, is opening the system browser the hard way, using java.lang.Runtime

for windows, your code will be

 Runtime.getRuntime().exec( "rundll32 url.dll,FileProtocolHandler " + url);

a very nice fully working code that covers OSX and Linux too can be be found here

Community
  • 1
  • 1
yannicuLar
  • 3,083
  • 3
  • 32
  • 50
0

From the documentation:

public static boolean isDesktopSupported()

Tests whether this class is supported on the current platform. If it's supported, use getDesktop() to retrieve an instance.

Returns: true if this class is supported on the current platform; false otherwise

To make it short: Windows 7 does not support this class

Community
  • 1
  • 1
MUG4N
  • 19,377
  • 11
  • 56
  • 83