1

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();

        }
    }
Lonzak
  • 9,334
  • 5
  • 57
  • 88
Rahul Shah
  • 141
  • 2
  • 12
  • What thread is this executed on? You're mixing JavaFX components and Swing components, and to do that you should be managing the threading properly (i.e. create and show the `JFileChooser` on the AWT Event dispatch thread, and create and show the `Stage` on the FX Application Thread). If this is a JavaFX Application, you should use a `javafx.stage.FileChooser` instead of the `JFileChooser`. No idea if this will fix the problem, it's probably unlikely (though certainly possible). – James_D Jan 12 '16 at 12:08
  • i mean, i dont know what else to do. it says loadPDF is the problem. the viewer pops up i just cant load anything – Rahul Shah Jan 13 '16 at 02:37
  • Why are you calling `pdfStage.showAndWait()` before you call `baseViewer.start(pdfStage);`? I don't know JPedal at all, but that just seems to make no sense. (There isn't anything in the window when you show it the first time.) – James_D Jan 13 '16 at 03:13
  • good point, thought that does not fix the problem, Ill edit that to reflect my actual code – Rahul Shah Jan 13 '16 at 03:39
  • Have you managed to fix this issue? – Klapsa2503 Apr 27 '16 at 11:42
  • turns out the library for OpenViewerFX was... incomplete. It just does not work. – Rahul Shah Apr 28 '16 at 01:23

0 Answers0