Win a copy of Practice Tests for OCP Java 17 Certification Exam (1Z0-829) this week in the OCPJP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

Opening a web page with Java problems(BrowserLauncher problems)

Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am currently trying to open a web page from an application. I have experience with I/O stream connections to web pages but not opening up the web page. BrowserLauncher was suggested to me, so I downloaded the BrowserLauncher class. I then tried to use test code to see if it would work. The BrowserLauncher class compiled, but my test class did not (this test class basically instanciated BrowserLauncher and called its openURL method to open a web page). When I tried to compile the test class, the Java compiler threw an exception that read "BrowserLauncher()
has private access in BrowserLauncher BrowserLauncher bl = new BrowserLauncher()." I was wondering if anyone had any ideas as why BrowserLauncher wasn't working or any other ideas on how to open up web pages in an application. Thanks.
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I Googled the right BrowserLauncher, it looks like all methods are static so you don't need to create an instance. Skip the "new BrowserLauncher()" line and just start calling methods on the class, e.g. BrowserLauncher.doThis()

For Windows only (!) I like to use the RunDLL32 approach. Exec something like

rundll32 url.dll,FileProtocolHandler

The "FileProtocolHandler" is exactly like clicking a file in Explorer or entering a filename as a command in a command prompt. It will launch the default browser even if it is some weird thing you've never heard of. Try that line in a command window to see it go.
    Bookmark Topic Watch Topic
  • New Topic