单击按钮时,我使用以下代码从java访问默认浏览器:
if( !java.awt.Desktop.isDesktopSupported() ) {
System.err.println( "Desktop is not supported (fatal)" );
}
java.awt.Desktop desktop = java.awt.Desktop.getDesktop();
if( !desktop.isSupported( java.awt.Desktop.Action.BROWSE ) ) {
System.err.println( "Desktop doesn't support the browse action (fatal)" );
}
String number = txtInCall.getText();
String uriString = "http://localwebserver/new?number="+number;
//number only contains numbers similar to 023456789
try {
java.net.URI uri = new java.net.URI( uriString );
desktop.browse( uri );
}
catch ( Exception ex ) {
System.err.println( ex.getMessage() );
}
该程序在Windows 7 Home Premium x64上运行良好。如果我在Windows XP Professional x32 SP3上测试它,控制台将返回:“在任何活动的激活上下文中找不到请求的查找键”。
我用Google搜索并发现,错误与Internet Explore有关。测试机器上的默认浏览器是Mozilla Firefox 6.0.2。我还检查了注册表,并为firefox.exe注册了http协议,我更新了IE。
The other question about this error对我也没有帮助。在XP机器上,单击总是返回上述错误。