Я пытаюсь создать панель поиска, используя JFXTextField в Javafx8.Но когда я добавляю FilteredList
и SortedList
в мой код, приложение больше не запускается, и вывод показывает следующее исключение:
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$154(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:748)
Caused by: javafx.fxml.LoadException: file:/C:/Users/Zed%20and%20White/Documents/NetBeansProjects/Project_EMS/dist/run1317715357/Project_EMS.jar!/project_ems/FrontEnd.fxml:22
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
at project_ems.Project_EMS.start(Project_EMS.java:23)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
... 1 more
Caused by: java.lang.NullPointerException
at javafx.collections.transformation.TransformationList.<init>(TransformationList.java:65)
at javafx.collections.transformation.FilteredList.<init>(FilteredList.java:66)
at javafx.collections.transformation.FilteredList.<init>(FilteredList.java:87)
at project_ems.FrontEndController.<init>(FrontEndController.java:44)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
at sun.reflect.misc.ReflectUtil.newInstance(ReflectUtil.java:51)
at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:927)
at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:971)
at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:220)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:744)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2707)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2527)
... 17 more
Exception running application project_ems.Project_EMS
Я следовал этому методу Создание поиска TextField для поиска втаблица Javafx
Вот мой код:
ObservableList:
private ObservableList<DataHandler_ExamsListing> EListingData;
Блок кода, который использует вышеприведенное наблюдаемоеСписок:
private void LoadEListingData(){
try {
DBE.resultSet = DBE.statement.executeQuery("SELECT * FROM Exam");
EListingData = FXCollections.observableArrayList();
while (DBE.resultSet.next()) {
EListingData.add(new DataHandler_ExamsListing(DBE.resultSet.getInt("ExamID"),DBE.resultSet.getString("ExamName"),DBE.resultSet.getString("ExamDate"),DBE.resultSet.getString("ExamComment")));
}
EListingTable.setItems(EListingData);
} catch (SQLException e) {
}
}
FilteredList и SortedList (оба являются глобальными):
private final FilteredList<DataHandler_ExamsListing> FilteredData = new FilteredList<>(EListingData);
private final SortedList<DataHandler_ExamsListing> sortedData = new SortedList<>(FilteredData);
SearchBar FXML:
@FXML // fx:id="SearchExam_Elisting"
private JFXTextField SearchExam_Elisting; // Value injected by FXMLLoader
ActionEvent на панели поиска:
@FXML
private void SearchExamList(ActionEvent event) {
SearchExam_Elisting.textProperty().addListener((observable, oldValue, newValue) -> {
FilteredData.setPredicate(DataHandler_ExamsListing -> {
if (newValue == null || newValue.isEmpty()) {
return true;
}
String lowerCaseFilter = newValue.toLowerCase();
if (DataHandler_ExamsListing.getExamName().toLowerCase().contains(lowerCaseFilter)) {
return true;
}
return false;
});
});
sortedData.comparatorProperty().bind(EListingTable.comparatorProperty());
EListingTable.setItems(sortedData);
System.out.println("DOne");
}
, если я закомментирую FilteredList
и SortedList
и ActionEvent
, приложение будет работать гладко.
Пожалуйста, помогите мне решить эту проблему. Спасибо!