4 Replies Latest reply: Aug 9, 2013 1:08 AM by 902665 RSS

    Cannot open PDF - file with my applet

    902665

      Hello OTN Community,

       

      i have a problem. I use the following method to open a PDF file.

       

      public static Integer openPDFFromFile(File file_) {
              try {
                  File pdfFile = file_;
                  if (pdfFile.exists()) {
                      if (Desktop.isDesktopSupported()) {
                          Desktop desktop = Desktop.getDesktop();
                          desktop.open(pdfFile);
                      } else {
                          System.out.println("Awt Desktop is not supported!");
                          return -1;
                      }
                  } else {
                      System.out.println("File is not exists!");
                      return -2;
                  }
                  System.out.println("Done");
                  return 0;
              } catch (IOException ex) {
                  Logger.getLogger(PDFmanagement.class.getName()).log(Level.SEVERE, null, ex);
                  return -1;
              }
          }

       

      On the desktop, it works, but if i will run my programm as an javafx-applet, i get the following error:

       

      java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
          at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1440)
          at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:69)
          at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:217)
          at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:170)
          at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:38)
          at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:37)
          at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
          at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
          at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
          at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
          at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
          at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
          at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
          at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
          at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
          at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
          at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
          at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
          at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
          at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
          at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
          at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
          at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
          at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:53)
          at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:28)
          at javafx.event.Event.fireEvent(Event.java:171)
          at javafx.scene.Node.fireEvent(Node.java:6863)
          at javafx.scene.control.Button.fire(Button.java:179)
          at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:193)
          at com.sun.javafx.scene.control.skin.SkinBase$4.handle(SkinBase.java:336)
          at com.sun.javafx.scene.control.skin.SkinBase$4.handle(SkinBase.java:329)
          at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:64)
          at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:217)
          at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:170)
          at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:38)
          at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:37)
          at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
          at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
          at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
          at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
          at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
          at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
          at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
          at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
          at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
          at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
          at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
          at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
          at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
          at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
          at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
          at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
          at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
          at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
          at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
          at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:53)
          at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:33)
          at javafx.event.Event.fireEvent(Event.java:171)
          at javafx.scene.Scene$MouseHandler.process(Scene.java:3328)
          at javafx.scene.Scene$MouseHandler.process(Scene.java:3168)
          at javafx.scene.Scene$MouseHandler.access$1900(Scene.java:3123)
          at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1563)
          at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2265)
          at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:250)
          at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:173)
          at java.security.AccessController.doPrivileged(Native Method)
          at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:292)
          at com.sun.glass.ui.View.handleMouseEvent(View.java:528)
          at com.sun.glass.ui.View.notifyMouse(View.java:922)
          at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
          at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
          at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:73)
          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.GeneratedMethodAccessor2.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)
          at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1437)
          ... 72 more
      Caused by: java.lang.NullPointerException
          at java.awt.Desktop.getDesktop(Unknown Source)
          at file.PDFmanagement.openPDFFromFile(PDFmanagement.java:92)
          at file.PDFmanagement.openPDF(PDFmanagement.java:84)
          at guiPersonal.PersonalQualificationController.openSchulzeugnis(PersonalQualificationController.java:256)
          at guiPersonal.PersonalQualificationController.btSchulabschlussOnAction(PersonalQualificationController.java:84)
          ... 82 more

       

      The error is in this line:

       

      Desktop desktop = Desktop.getDesktop();

       

      My applet has the security level "all-permission" and i know, in the past, it have worked.

       

      I hope, somebody can help me.

        • 1. Re: Cannot open PDF - file with my applet
          Aeros94

          Since yesterday( 2 july 2013), i have the same error, same stack.

          Using signed jar and 'all-permission'.

          It worked before.

           

           

          More information, Desktop.isDesktopSupported() retur 'true'.

           

          May be someone can help us.

           

          Thanks in advance.

          • 2. Re: Cannot open PDF - file with my applet
            902665

            Hello again. After i had read some informations about 7u25 and add the missing manifest-values (Codebase, Permission and additional Trusted-Library), it dont work. I dont understand it. Is it a bug ?

            • 3. Re: Cannot open PDF - file with my applet
              137a13fb-e9e6-4933-a052-fbd2009726f7

              Same issue here as well, any solutions?  Bumping issue.

              • 4. Re: Cannot open PDF - file with my applet
                902665

                After a long time to find a solution, we use a workaround, thats only work on windows system. I hope, with the next release, it will work again.

                 

                Hier is the workaround:

                 

                if (Desktop.isDesktopSupported()) {

                                    Desktop desktop = Desktop.getDesktop();

                                    if(desktop == null){

                                        // Since Java 7u25, we get a nullpointer at this point.

                                        // So if we have a nullpointer, we will use this alternative (only for windows)

                                        Runtime.getRuntime().exec( "cmd /C "+pdfFile.getAbsolutePath() );

                                    }else{

                                        desktop.open(pdfFile);

                                    }

                                } else {

                                    System.out.println("Awt Desktop is not supported!");

                                    return -1;

                                }