Ubuntu试图打开JavaFX保存对话框或打开对话框时JVM崩溃
在Windows中,一切正常,我只是使用JavaFX和Java1.8.0131从操作系统中选择一个文件Ubuntu试图打开JavaFX保存对话框或打开对话框时JVM崩溃,java,linux,ubuntu,javafx,Java,Linux,Ubuntu,Javafx,在Windows中,一切正常,我只是使用JavaFX和Java1.8.0131从操作系统中选择一个文件 # # A fatal error has been detected by the Java Runtime Environment: # # SIGSEGV (0xb) at pc=0x00007fa5f45cde90, pid=4843, tid=0x00007fa59b31c700 # # JRE version: Java(TM) SE Runtime Environment (8
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007fa5f45cde90, pid=4843, tid=0x00007fa59b31c700
#
# JRE version: Java(TM) SE Runtime Environment (8.0_131-b11) (build 1.8.0_131-b11)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.131-b11 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C [libpthread.so.0+0x9e90] pthread_mutex_lock+0x0
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /home/alexander/Desktop/Roots/hs_err_pid4843.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
Aborted (core dumped)
您可以使用的代码:
import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
public final class FileChooserSample extends Application {
private Desktop desktop = Desktop.getDesktop();
@Override
public void start(final Stage stage) {
stage.setTitle("File Chooser Sample");
final FileChooser fileChooser = new FileChooser();
final Button openButton = new Button("Open a Picture...");
final Button openMultipleButton = new Button("Open Pictures...");
openButton.setOnAction(
new EventHandler<ActionEvent>() {
@Override
public void handle(final ActionEvent e) {
configureFileChooser(fileChooser);
File file = fileChooser.showOpenDialog(stage);
if (file != null) {
openFile(file);
}
}
});
openMultipleButton.setOnAction(
new EventHandler<ActionEvent>() {
@Override
public void handle(final ActionEvent e) {
configureFileChooser(fileChooser);
List<File> list =
fileChooser.showOpenMultipleDialog(stage);
if (list != null) {
for (File file : list) {
openFile(file);
}
}
}
});
final GridPane inputGridPane = new GridPane();
GridPane.setConstraints(openButton, 0, 0);
GridPane.setConstraints(openMultipleButton, 1, 0);
inputGridPane.setHgap(6);
inputGridPane.setVgap(6);
inputGridPane.getChildren().addAll(openButton, openMultipleButton);
final Pane rootGroup = new VBox(12);
rootGroup.getChildren().addAll(inputGridPane);
rootGroup.setPadding(new Insets(12, 12, 12, 12));
stage.setScene(new Scene(rootGroup));
stage.show();
}
public static void main(String[] args) {
Application.launch(args);
}
private static void configureFileChooser(final FileChooser fileChooser){
fileChooser.setTitle("View Pictures");
fileChooser.setInitialDirectory(
new File(System.getProperty("user.home"))
);
}
private void openFile(File file) {
try {
desktop.open(file);
} catch (IOException ex) {
Logger.getLogger(
FileChooserSample.class.getName()).log(
Level.SEVERE, null, ex
);
}
}
}
导入java.awt.Desktop;
导入java.io.File;
导入java.io.IOException;
导入java.util.List;
导入java.util.logging.Level;
导入java.util.logging.Logger;
导入javafx.application.application;
导入javafx.event.ActionEvent;
导入javafx.event.EventHandler;
导入javafx.geometry.Insets;
导入javafx.scene.scene;
导入javafx.scene.control.Button;
导入javafx.scene.layout.GridPane;
导入javafx.scene.layout.Pane;
导入javafx.scene.layout.VBox;
导入javafx.stage.FileChooser;
导入javafx.stage.stage;
公共最终类FileChooserSample扩展应用程序{
私有桌面=Desktop.getDesktop();
@凌驾
公共作废开始(最后阶段){
stage.setTitle(“文件选择器示例”);
最终文件选择器FileChooser=新文件选择器();
最终按钮打开按钮=新按钮(“打开图片…”);
最终按钮openMultipleButton=新建按钮(“打开图片…”);
openButton.setOnAction(
new EventHandler你的内核版本是什么?我记得看到过关于内核最近引入的一个bug的报告,该bug在某些情况下破坏了Java。请参阅,例如:@sillyfly我有最新的Ubuntu版本Ubuntu 17.04。这也适用于17.04。请参阅(不确定你看到的是同一个问题,但仅仅是在17.04并不意味着它不是那样的)。@sillyfly O_O谢谢:)我会试试。