javafx FileChooser Mac OS NSInternalInconsistencyException

陌路散爱 提交于 2019-12-10 18:51:19

问题


I am trying to open a fileChooser using javafx FileChooser I'm assigning a listner to the FXML button via the controller the application loads fine, however when I click the button the file chooser opens followed promptly by a crash.

This is driving me nuts, I think it is todo with the implementation of the xcode interface from java, however I am totally lost on this one.

Has anymore come across this before when using JavaFx ??

my stack trace is:

012-12-06 23:24:02.732 java[16800:707] Invalid parameter not satisfying: cgsEvent.type > 0 && cgsEvent.type <= kCGSLastEventType
2012-12-06 23:24:02.733 java[16800:707] (
0   CoreFoundation                      0x00007fff8b8c20a6 __exceptionPreprocess + 198
1   libobjc.A.dylib                     0x00007fff858393f0 objc_exception_throw + 43
2   CoreFoundation                      0x00007fff8b8c1ee8 +[NSException raise:format:arguments:] + 104
3   Foundation                          0x00007fff89f926a2 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 189
4   AppKit                              0x00007fff85d5356c -[NSEvent _initWithCGSEvent:eventRef:] + 2782
5   AppKit                              0x00007fff85fd43ea +[NSEvent eventWithCGEvent:] + 243
6   libglass.dylib                      0x00000001630e300f listenTouchEvents + 31
7   CoreGraphics                        0x00007fff8be07115 processEventTapData + 150
8   CoreGraphics                        0x00007fff8be06f68 _CGYPostEventTapData + 189
9   CoreGraphics                        0x00007fff8be0c26a _XPostEventTapData + 107
10  CoreGraphics                        0x00007fff8be0c362 CGYEventTap_server + 106
11  CoreGraphics                        0x00007fff8be07056 eventTapMessageHandler + 30
12  CoreFoundation                      0x00007fff8b831410 __CFMachPortPerform + 288
13  CoreFoundation                      0x00007fff8b8312d9 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 41
14  CoreFoundation                      0x00007fff8b831019 __CFRunLoopDoSource1 + 153
15  CoreFoundation                      0x00007fff8b86419f __CFRunLoopRun + 1775
16  CoreFoundation                      0x00007fff8b8636b2 CFRunLoopRunSpecific + 290
17  HIToolbox                           0x00007fff882d40a4 RunCurrentEventLoopInMode + 209
18  HIToolbox                           0x00007fff882d3d84 ReceiveNextEventCommon + 166
19  HIToolbox                           0x00007fff882d3cd3 BlockUntilNextEventMatchingListInMode + 62
20  AppKit                              0x00007fff85c74613 _DPSNextEvent + 685
21  AppKit                              0x00007fff85c73ed2 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 128
22  libglass.dylib                      0x00000001630ce8c3 +[GlassApplication enterNestedEventLoopWithEnv:] + 163
23  libglass.dylib                      0x00000001630d24d3 -[DialogDispatcher runModal] + 163
24  Foundation                          0x00007fff8a012220 -[NSObject(NSThreadPerformAdditions) performSelector:onThread:withObject:waitUntilDone:modes:] + 212
25  Foundation                          0x00007fff8a0120c8 -[NSObject(NSThreadPerformAdditions) performSelectorOnMainThread:withObject:waitUntilDone:] + 131
26  libglass.dylib                      0x00000001630d29c5 Java_com_sun_glass_ui_mac_MacCommonDialogs__1showFileOpenChooser + 981
27  ???                                 0x0000000101dc3f90 0x0 + 4326178704
)
2012-12-06 23:24:02.734 java[16800:707] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: cgsEvent.type > 0 && cgsEvent.type <= kCGSLastEventType'

First throw call stack:

(
0   CoreFoundation                      0x00007fff8b8c20a6 __exceptionPreprocess + 198
1   libobjc.A.dylib                     0x00007fff858393f0 objc_exception_throw + 43
2   CoreFoundation                      0x00007fff8b8c1ee8 +[NSException raise:format:arguments:] + 104
3   Foundation                          0x00007fff89f926a2 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 189
4   AppKit                              0x00007fff85d5356c -[NSEvent _initWithCGSEvent:eventRef:] + 2782
5   AppKit                              0x00007fff85fd43ea +[NSEvent eventWithCGEvent:] + 243
6   libglass.dylib                      0x00000001630e300f listenTouchEvents + 31
7   CoreGraphics                        0x00007fff8be07115 processEventTapData + 150
8   CoreGraphics                        0x00007fff8be06f68 _CGYPostEventTapData + 189
9   CoreGraphics                        0x00007fff8be0c26a _XPostEventTapData + 107
10  CoreGraphics                        0x00007fff8be0c362 CGYEventTap_server + 106
11  CoreGraphics                        0x00007fff8be07056 eventTapMessageHandler + 30
12  CoreFoundation                      0x00007fff8b831410 __CFMachPortPerform + 288
13  CoreFoundation                      0x00007fff8b8312d9 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 41
14  CoreFoundation                      0x00007fff8b831019 __CFRunLoopDoSource1 + 153
15  CoreFoundation                      0x00007fff8b86419f __CFRunLoopRun + 1775
16  CoreFoundation                      0x00007fff8b8636b2 CFRunLoopRunSpecific + 290
17  HIToolbox                           0x00007fff882d40a4 RunCurrentEventLoopInMode + 209
18  HIToolbox                           0x00007fff882d3d84 ReceiveNextEventCommon + 166
19  HIToolbox                           0x00007fff882d3cd3 BlockUntilNextEventMatchingListInMode + 62
20  AppKit                              0x00007fff85c74613 _DPSNextEvent + 685
21  AppKit                              0x00007fff85c73ed2 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 128
22  libglass.dylib                      0x00000001630ce8c3 +[GlassApplication enterNestedEventLoopWithEnv:] + 163
23  libglass.dylib                      0x00000001630d24d3 -[DialogDispatcher runModal] + 163
24  Foundation                          0x00007fff8a012220 -[NSObject(NSThreadPerformAdditions) performSelector:onThread:withObject:waitUntilDone:modes:] + 212
25  Foundation                          0x00007fff8a0120c8 -[NSObject(NSThreadPerformAdditions) performSelectorOnMainThread:withObject:waitUntilDone:] + 131
26  libglass.dylib                      0x00000001630d29c5 Java_com_sun_glass_ui_mac_MacCommonDialogs__1showFileOpenChooser + 981
27  ???                                 0x0000000101dc3f90 0x0 + 4326178704
)
libc++abi.dylib: terminate called throwing an exception

The Controller code is:

public class AppController implements Initializable {

@FXML
private TableView<Transactions> tableTranactions;
@FXML
private TableColumn<Transactions, Integer> accountID;
@FXML
private TableColumn<Transactions, String> colTranDate;
@FXML
private TableColumn<Transactions, String> colDescription;
@FXML
private TableColumn<Transactions, Double> colAmount;
@FXML
private TableColumn<Transactions, Integer> colCompany;
@FXML
private TableColumn<Transactions, String> colTransType;
@FXML
private Button btnClear;
@FXML
private Button btnFileChoose;
@FXML
private LineChart<String, Double> chartLineSpendingByMonth;
@FXML
private Pane paneGraph;
@FXML
private Pane paneGraphWeek;
@FXML
private Pane paneAddRecord;
@FXML
private PieChart pieSpendingCatalogue;
@FXML
private Label lblTransactions;
@FXML 
private TextField txtFilePath;

@Override
public void initialize(URL arg0, ResourceBundle arg1) {
    // TODO Auto-generated method stub
    System.out.println("starting application");
    showTransactions();
    btnFileChoose.setOnAction(new EventHandler<ActionEvent>() {
    /**
        WHAT IS CAUSING THIS CODE SEGMENT TO FAIL??? **/
    @Override
        public void handle(ActionEvent event) {
            FileChooser fileChooser = new FileChooser();
            fileChooser.setTitle("Select File");
            //Set extension filter
            FileChooser.ExtensionFilter extFilter =
                    new FileChooser.ExtensionFilter("CSV", ".csv");
            fileChooser.getExtensionFilters().add(extFilter);
            //Show open file dialog
            File file = fileChooser.showOpenDialog(null);
           if(file!=null)
               txtFilePath.setText(file.getPath());
        }
    });

}

@FXML
private void showTransactions()
{
    hideAll();
    tableTranactions.setVisible(true);
    btnClear.setVisible(true);

    accountID.setCellValueFactory(new PropertyValueFactory<Transactions, Integer>("accountid"));
    colTranDate.setCellValueFactory(new PropertyValueFactory<Transactions, String>("tranDate"));
    colDescription.setCellValueFactory(new PropertyValueFactory<Transactions, String>("descrip"));
    colAmount.setCellValueFactory(new PropertyValueFactory<Transactions, Double>("amount"));
    colCompany.setCellValueFactory(new PropertyValueFactory<Transactions, Integer>("comid"));
    colTransType.setCellValueFactory(new PropertyValueFactory<Transactions, String>("transType"));

    updateTransactionData();
}

public void hideAll()
{
    tableTranactions.setVisible(false);
    btnClear.setVisible(false);
    paneGraph.setVisible(false);
    paneGraphWeek.setVisible(false);
    paneAddRecord.setVisible(false);
}

public void clearTable()
{
    ObservableList<Transactions> data = tableTranactions.getItems();
    data.removeAll(data);

}
public void updateTransactionData()
{
    TransactionDAO trans = new TransactionDAO();
    ObservableList<Transactions> data = tableTranactions.getItems();
    data.addAll(trans.getAll());
}

public void showAddRecord()
{
    hideAll();

    paneAddRecord.setVisible(true);
}

public void showHistoric()
{
    hideAll();
    CatalogueSpendingDAO catalogue = new CatalogueSpendingDAO();

    ObservableList<PieChart.Data> data = pieSpendingCatalogue.getData();
    ObservableList<CatalogueSpending_total> values = catalogue.getTotal();
    data.removeAll(data);
    for(CatalogueSpending_total i : values)
        {
            data.add(new PieChart.Data(i.getDescription(), i.getTotal()));
        }
    // start adding line chart
    ObservableList<XYChart.Series<String, Double>> spendingByMonthData = chartLineSpendingByMonth.getData();
    Boolean add = false;

    if(spendingByMonthData.size() > 0)
        spendingByMonthData.removeAll(spendingByMonthData);

    XYChart.Series<String, Double> series =  (spendingByMonthData.size() > 0 ? spendingByMonthData.get(0): null);
    if(series == null)
    {
        series = new XYChart.Series<String, Double>();
        add = true;
    }
    SpendingByMonthDAO spendingByMonthDAO = new SpendingByMonthDAO();
    ObservableList<SpendingByMonth> spendingByMonthDatabase =  spendingByMonthDAO.getTotal();

    for(SpendingByMonth i : spendingByMonthDatabase)
    {
        series.getData().add(new XYChart.Data<String, Double>(i.getDate(), i.getTotal()));
    }
    spendingByMonthData.size();
    spendingByMonthData.add(0,series);
    pieSpendingCatalogue.animatedProperty();
    paneGraph.setVisible(true);
}

public void showWeeklyCharts()
{
    hideAll();
    //TODO populate the graphs here
    paneGraphWeek.setVisible(true);
}

}

System Information

  • java version: Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
  • OS: OS X 10.8.2

回答1:


SOLVED:

Runtime compiler was a much older version of hava Java 1.7.0

Also found this link:

https://forums.oracle.com/forums/thread.jspa?threadID=2444130

It seems once I updated the jdk via http://jdk7.java.net/download.html to java version 7u10 Build b18 the problem goes away :-)



来源:https://stackoverflow.com/questions/13754862/javafx-filechooser-mac-os-nsinternalinconsistencyexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!