Wre*_*ren 21 java linux netbeans javafx gnome-3
我在Ubuntu 12.04 LTS 64 Bit(使用Gnome Shell)上使用Java JDK 1.8.0_05通过NetBeans8.0在Java中运行一些代码.
当在Main或其他空Java项目中调用时,以下函数可以正常工作,但是当从任何JavaFX应用程序调用时,它会导致窗口冻结并停止响应(尽管项目完全符合),要求它强制关闭.
任何人都可以建议我写的可能导致问题或循环的问题吗?
唉,由于失败的模式,我没有提供或分析的错误信息.
感谢任何建议,提前感谢.
public static void desktopTest(){
Desktop de = Desktop.getDesktop();
try {
de.browse(new URI("http://stackoverflow.com"));
}
catch (IOException | URISyntaxException e) {
System.out.println(e);
}
try {
de.open(new File("/home/aaa/file.ext"));
}
catch (IOException e){
System.out.println(e);
}
try {
de.mail(new URI("mailto:email@example.com"));
}
catch (URISyntaxException | IOException e){
System.out.println(e);
}
}
Run Code Online (Sandbox Code Playgroud)
Ale*_*x K 33
我也有同样的问题,这个解决方案对我有用:
if( Desktop.isDesktopSupported() )
{
new Thread(() -> {
try {
Desktop.getDesktop().browse( new URI( "http://..." ) );
} catch (IOException | URISyntaxException e1) {
e1.printStackTrace();
}
}).start();
}
Run Code Online (Sandbox Code Playgroud)