0 Replies Latest reply: Apr 24, 2013 8:27 PM by 1005336 RSS

    DownloadServiceListener  Interface

      Hi (first time in this forum and new to java)

      I downloaded the program (webstart_CustomProgressIndicator) from the Java Tutorial, but when I tried to test it I got this error:

      Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
           at customprogressindicator.CustomProgress$2.run(CustomProgress.java:91)

      I put some messages to see what methods from the interface DownloadServiceListener are called and I noticed that only the method <font color="red"> validating </font> is the only one that is called, and the parameter <font color="red">overallPercent</font> starts with a value of 100, this caused the error because the program is trying to close the frame without a value assigned to it first. I do not know why the others methods are not called and overallPercent starts with 100.

      I hope somebody could guide me on this

      I am using this with another example (webstart_AppWithCustomProgressIndicator) and a JNLP file

      This is the program code
      import javax.jnlp.DownloadServiceListener;
      import java.awt.Color;
      import java.awt.BorderLayout;
      import javax.swing.*;
      import java.net.URL;
      public class CustomProgress implements DownloadServiceListener {   
          JFrame frame = null;
          JProgressBar progressBar = null;
          boolean uiCreated = false;
          public CustomProgress() {       
          public void downloadFailed(java.net.URL url, java.lang.String version) {
          public void progress(URL url, String version, long readSoFar,
                               long total, int overallPercent) {        
          public void upgradingArchive(java.net.URL url,
                            java.lang.String version,
                            int patchPercent,
                            int overallPercent) {
          public  void validating(java.net.URL url,   
                      java.lang.String version,
                      long entry,
                      long total,
                      int overallPercent) {
          private void updateProgressUI(int overallPercent) {
              if (overallPercent > 0 && overallPercent < 99) {
                  if (!uiCreated) {
                      uiCreated = true;
                      // create custom progress indicator's UI only if 
                      // there is more work to do, meaning overallPercent > 0 and < 100
                      // this prevents flashing when RIA is loaded from cache
                  SwingUtilities.invokeLater(new Runnable() {
                      public void run() {
              } else {
                  // hide frame when overallPercent is above 99
                  SwingUtilities.invokeLater(new Runnable() {
                      public void run() {
                          frame.setVisible(false); "****this is the line with the error****"
          private void create() {
              JPanel top = createComponents();
              frame = new JFrame(); // top level custom progress indicator UI
              frame.getContentPane().add(top, BorderLayout.CENTER);
          private JPanel createComponents() {
              JPanel top = new JPanel();
              top.setLayout(new BorderLayout(20, 20));
              String lblText = "<html><font color=red size=+2>JDK Documentation</font><br/> The one-stop shop for Java enlightenment! <br/></html>";
              JLabel lbl = new JLabel(lblText);
              top.add(lbl, BorderLayout.NORTH);
              lbl = new JLabel();
              ImageIcon logo = createImageIcon("images/DukeWithHelmet.png", "logo");
              top.add(lbl, BorderLayout.EAST);
              lbl = new JLabel("<html><font color=green size=-2>Loading application...</font></html>");
              top.add(lbl, BorderLayout.CENTER);
              progressBar = new JProgressBar(0, 100);
              top.add(progressBar, BorderLayout.SOUTH);
              return top;
          /** Returns an ImageIcon, or null if the path was invalid. */
          protected static ImageIcon createImageIcon(String path,
                                                     String description) {
              java.net.URL imgURL = CustomProgress.class.getResource(path);
              if (imgURL != null) {
                  return new ImageIcon(imgURL, description);
              } else {
                  System.err.println("Couldn't find file: " + path);
                  return null;
      This is the JNLP file
      <?xml version="1.0" encoding="utf-8"?>
      <!-- Custom Progress bar Demo Application; also contains splash image used when application is loaded from cache -->
      <jnlp spec="1.0+" codebase=""
          <title>Weather Application With Custom Progress Bar</title>
          <description>custom progress bar example</description>
          <icon kind="splash" href="dukeanimated.gif"/>    
          <j2se version="1.6+"/>
          <jar href="webstart_AppWithCustomProgressIndicator.jar" />
          <jar href="../../webstart_CustomProgressIndicator/dist/webstart_CustomProgressIndicator.jar"
               download="progress" />
          <jar href="../lib/IconDemo.jar" />
          <jar href="../lib/SplitPaneDemo.jar" />
          <jar href="../lib/SplitPaneDemo2.jar" />
          <jar href="../lib/TextBatchPrintingDemo.jar" />
          <jar href="../lib/ToolBarDemo.jar" />
          <jar href="../lib/ToolBarDemo2.jar" />
          <jar href="../lib/SwingSet2.jar" />
          <jar href="../lib/SomeBigJar.jar" />