Desktop.open(文件),Desktop.browse(uri)上的JavaFX Freeze [英] JavaFX Freeze on Desktop.open(file), Desktop.browse(uri)

查看:174
本文介绍了Desktop.open(文件),Desktop.browse(uri)上的JavaFX Freeze的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Ubuntu 12.04 LTS 64 Bit(使用Gnome Shell)上使用Java JDK 1.8.0_05通过NetBeans8.0在Java中运行一些代码。



当在Main或其他空Java项目中调用时,以下函数可以正常工作,但是当从任何JavaFX应用程序调用时,它会导致窗口冻结并停止响应(尽管项目完全符合要求),要求它强制关闭。 / p>

任何人都可以建议我写的可能导致问题或循环的任何问题吗?



唉,由于失败的模式,没有我可以提供或分析的错误信息。



感谢任何建议,提前感谢。

  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);
}
尝试{
de.mail(新URI(mailto:email@example.com));
}
catch(URISyntaxException | IOException e){
System.out.println(e);
}
}


解决方案

我也有同样的问题,这个解决方案适合我:

  if(Desktop.isDesktopSupported())
{
new Thread(() - > {
try {
Desktop.getDesktop()。browse(new URI(http:// ...));
} catch(IOException | URISyntaxException e1){
e1.printStackTrace();
}
})。start();
}


I'm running some code in Java on Ubuntu 12.04 LTS 64 Bit (with Gnome Shell), using Oracle JDK 1.8.0_05 via NetBeans8.0.

The following function works perfectly when called either in Main or in an otherwise empty Java Project, however when called from any JavaFX application, it causes the window to freeze and stop responding (although the project complies perfectly), requiring it to be Force Closed.

Can anyone suggest any issues with what I've written which might be causing an issue or loop?

Alas, due to the mode of failure, there is no error message that I can supply or analyse.

Any suggestions gratefully received, thanks in advance.

   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);
            }
}

解决方案

I also had the same problem and this solution works for me:

if( Desktop.isDesktopSupported() )
{
    new Thread(() -> {
           try {
               Desktop.getDesktop().browse( new URI( "http://..." ) );
           } catch (IOException | URISyntaxException e1) {
               e1.printStackTrace();
           }
       }).start();
}

这篇关于Desktop.open(文件),Desktop.browse(uri)上的JavaFX Freeze的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆