我正在Ubuntu12.04LTS 64位(使用Gnome )上运行一些代码,通过NetBeans8.0使用Oracle 1.8.0_05。
无论是在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);
}
}发布于 2015-12-23 05:16:22
我也有同样的问题,这个解决方案对我来说是有效的:
if( Desktop.isDesktopSupported() )
{
new Thread(() -> {
try {
Desktop.getDesktop().browse( new URI( "http://..." ) );
} catch (IOException | URISyntaxException e1) {
e1.printStackTrace();
}
}).start();
}发布于 2015-06-11 20:02:28
我解决了.
public static void abrirArquivo(File arquivo) {
if (arquivo != null) {
if (arquivo.exists()) {
OpenFile openFile = new OpenFile(arquivo);
Thread threadOpenFile = new Thread(openFile);
threadOpenFile.start();
}
}
}
private static class OpenFile implements Runnable {
private File arquivo;
public OpenFile(File arquivo) {
this.arquivo = arquivo;
}
private void abrirArquivo(File arquivo) throws IOException {
if (arquivo != null) {
java.awt.Desktop.getDesktop().open(arquivo);
}
}
@Override
public void run() {
// TODO Auto-generated method stub
try {
abrirArquivo(arquivo);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}发布于 2014-04-27 08:05:27
我也有同样的问题。我发现,如果我从一个新线程调用Desktop.open()方法,那么在关闭JavaFX应用程序窗口后,该文件将打开,但这并没有多大帮助。
如果你把
SwingUtilities.invokeLater(() -> System.out.println("Hello world"));在启动后的主要方法(Args)调用中,在关闭JavaFX应用程序之前,它也不会被调用。
JavaFX应用程序和Swing之间似乎存在某种并发问题。
在Ubuntu上你可以试试
xdg-open filename从你的JavaFX应用程序。
据我所知,您的代码应该可以工作。
https://stackoverflow.com/questions/23176624
复制相似问题