In openviewerFX, when I call JFileChooser to save my pdf, it saves, but right after that, it is supposed to open a BaseViewerFX window and display said saved PDF. When I run the program however, JFileChooser comes up, it saves, and then when it is time to call the .loadPDF method, it returns a null pointer exception, even though the file is initialized in the if block. The error(s) are as follows:
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at javafx.fxml.FXMLLoader$MethodHandler.invoke(Unknown Source)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(Unknown Source)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
at javafx.event.Event.fireEvent(Unknown Source)
at javafx.scene.Node.fireEvent(Unknown Source)
at javafx.scene.control.Button.fire(Unknown Source)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(Unknown Source)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(Unknown Source)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(Unknown Source)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(Unknown Source)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
at javafx.event.Event.fireEvent(Unknown Source)
at javafx.scene.Scene$MouseHandler.process(Unknown Source)
at javafx.scene.Scene$MouseHandler.access$1500(Unknown Source)
at javafx.scene.Scene.impl_processMouseEvent(Unknown Source)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$354(Unknown Source)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(Unknown Source)
at com.sun.glass.ui.View.handleMouseEvent(Unknown Source)
at com.sun.glass.ui.View.notifyMouse(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.reflect.misc.Trampoline.invoke(Unknown Source)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.reflect.misc.MethodUtil.invoke(Unknown Source)
... 53 more
Caused by: java.lang.NullPointerException
at org.jpedal.examples.baseviewer.BaseViewerFX.start(Unknown Source)
at fbla.rahulshah.database.dataManipulation.PDFCreationAndViewerLauncher.createDebtorPDF(PDFCreationAndViewerLauncher.java:53)
at fbla.rahulshah.database.view.MainScreenController.generateDebtReport(MainScreenController.java:114)
... 62 more
Qt: Untested Windows version 10.0 detected!
Qt: Untested Windows version 10.0 detected!
Qt: Untested Windows version 10.0 detected!
Qt: Untested Windows version 10.0 detected!
Qt: Untested Windows version 10.0 detected!
Qt: Untested Windows version 10.0 detected!
Qt: Untested Windows version 10.0 detected!
Qt: Untested Windows version 10.0 detected!
Qt: Untested Windows version 10.0 detected!
Qt: Untested Windows version 10.0 detected!
Qt: Untested Windows version 10.0 detected!
Qt: Untested Windows version 10.0 detected!
Qt: Untested Windows version 10.0 detected!
Qt: Untested Windows version 10.0 detected!
Qt: Untested Windows version 10.0 detected!
Qt: Untested Windows version 10.0 detected!
Qt: Untested Windows version 10.0 detected!
Qt: Untested Windows version 10.0 detected!
Qt: Untested Windows version 10.0 detected!
Qt: Untested Windows version 10.0 detected!
Qt: Untested Windows version 10.0 detected!
Qt: Untested Windows version 10.0 detected!
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at org.jpedal.examples.baseviewer.BaseViewerFX.openFile(Unknown Source)
at org.jpedal.examples.baseviewer.BaseViewerFX.loadPDF(Unknown Source)
at org.jpedal.examples.baseviewer.BaseViewerFX$7$1.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(Unknown Source)
at java.lang.Thread.run(Unknown Source)
As you can see, it is giving me a null pointer exception, along with this weird QT untested thing (i ignore it because i looked up what it was, and it is apparently not important). Even when I try to open it using the Open button on the BaseViewerFX window it does the same thing. I realize that nullPointerExceptions are something that can be easily fixed and are caused by the variable not being initialized, but the variable is initialized inside the if block it was created in. Taking it out of the if block does not do anything either. Here is the code to see for yourself:
public void createDebtorPDF() throws Exception {
File file;
JFileChooser fileChooser = new JFileChooser();
ArrayList<StudentData> listOfDebtors = new ArrayList<StudentData>();
int i = 0;
listOfDebtors = StudentData.getListOfDebtors(i, listOfDebtors);
PDDocument debtorDoc = new PDDocument();
PDPage page = new PDPage();
debtorDoc.addPage(page);
createPDF(debtorDoc, page, i, listOfDebtors, i);
Stage pdfStage = new Stage();
BaseViewerFX baseViewer = new BaseViewerFX();
if (fileChooser.showSaveDialog(fileChooser) == JFileChooser.APPROVE_OPTION) {
file = fileChooser.getSelectedFile();
file = checkFileName(file);
file = fileChooser.showSaveDialog(null);
file = checkFileName(file);
baseViewer.init();
debtorDoc.save(file);
pdfStage.setScene(baseViewer.setupViewer(600, 400));
baseViewer.setupViewer(600, 400);
pdfStage.show();
baseViewer.loadPDF(file);
baseViewer.start(pdfStage);
debtorDoc.close();
}
}