Я создаю приложение JavaFX FXMl с Hibernate как ORM в Java. Я хочу прочитать данные из Excel и сохранить их в MySQL, используя hibernate, но при этом не удается создать рабочую книгу.
У меня есть часы, чтобы прочитать учебные пособия и другие сообщения, будь то на SO или других сайтах, ни принятые ответы, ни комментарии не помогли мне.
В моем файле Form_Main.fxml
есть кнопка, которая вызывает связанный метод для чтения данных из Excel. Я добавил следующие файлы JAR:
* poi-4.1.0
* poi-ooxml-4.1.0
* poi-ooxml-schemas-4.1.0
* xmlbeans-3.0.1
* commons-collection4-4.2
к проекту. Мой импорт для чтения данных выглядит следующим образом:
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFRow;
метод, который я определил:
FileInputStream _File = new FileInputStream(new File("D:\\Students_Info.xlsx"));
XSSFWorkbook _Workbook = new XSSFWorkbook(_File);
XSSFSheet _Sheet = _Workbook.getSheetAt(0);
XSSFRow _Row;
Остальная часть кода собирается записывать данные в MySQL с помощью hibernate. Но это не работает.
Когда я отлаживаю свою программу, в строке:
XSSFWorkbook _Workbook = new XSSFWorkbook(_File);
Переход к файлу FXMLLoader.java
в строке:
catch (InvocationTargetException exception) {
throw new RuntimeException(exception);
}
Моя трассировка стека (если я прав):
[java] Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
[java] at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1774)
[java] at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
[java] at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
[java] at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
[java] at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
[java] at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
[java] at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
[java] at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
[java] at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
[java] at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
[java] at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
[java] at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
[java] at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
[java] at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
[java] at javafx.event.Event.fireEvent(Event.java:198)
[java] at javafx.scene.Node.fireEvent(Node.java:8411)
[java] at javafx.scene.control.Button.fire(Button.java:185)
[java] at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
[java] at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
[java] at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
[java] at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
[java] at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
[java] at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
[java] at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
[java] at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
[java] at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
[java] at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
[java] at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
[java] at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
[java] at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
[java] at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
[java] at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
[java] at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
[java] at javafx.event.Event.fireEvent(Event.java:198)
[java] at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
[java] at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
[java] at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
[java] at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
[java] at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:394)
[java] at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
[java] at java.security.AccessController.doPrivileged(Native Method)
[java] at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$358(GlassViewEventHandler.java:432)
[java] at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:410)
[java] at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:431)
[java] at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
[java] at com.sun.glass.ui.View.notifyMouse(View.java:937)
[java] at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
[java] at com.sun.glass.ui.win.WinApplication.lambda$null$152(WinApplication.java:177)
[java] at java.lang.Thread.run(Thread.java:748)
[java] Caused by: java.lang.reflect.InvocationTargetException
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[java] at java.lang.reflect.Method.invoke(Method.java:498)
[java] at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
[java] at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[java] at java.lang.reflect.Method.invoke(Method.java:498)
[java] at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
[java] at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1771)
[java] ... 48 more
[java] Caused by: java.lang.NoClassDefFoundError: org/apache/commons/collections4/ListValuedMap
[java] at school_system.Model.TblStudent.importDataFromFile(TblStudent.java:107)
[java] at school_system.Controllers.Controller_Main.handleImportDataButtonAction(Controller_Main.java:34)
[java] ... 58 more
[java] Caused by: java.lang.ClassNotFoundException: org.apache.commons.collections4.ListValuedMap
[java] at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[java] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[java] ... 60 more