JavaFX Freeze on Desktop.open(file), Desktop.browse(uri) [英] JavaFX Freeze on Desktop.open(file), Desktop.browse(uri)

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

问题描述

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

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.

以下函数在 Main 或其他空的 Java 项目中调用时可以完美运行,但是从任何 JavaFX 应用程序调用时,它会导致窗口冻结并停止响应(尽管项目完全符合),需要它强制关闭.

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

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

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