1

This applet works fine when I use it in a browser, but why doesn't it work with the applet viewer?

I have tried using both jGRASP and Eclipse to view the applet but whatever I do, I get this:

java.lang.NumberFormatException: null on this line of code

int paramCount = Integer.parseInt( getParameter( "count" ) );

I dont understand why it is doing this.

//file: AppletParameters.java

import javax.swing.JApplet;
import javax.swing.JApplet;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
import java.awt.GridLayout;

public class AppletParameters extends JApplet
{
    private JPanel panel; // panel to display pictures

    public void init( )
    {
        // get the parameter count from the html 'count' parameter
        int paramCount = Integer.parseInt( getParameter( "count" ) );
        // create an array
        ImageIcon [] image = new ImageIcon[paramCount];
        // get each file name from the html 'file' parameter and put into array
        for ( int k=0; k<paramCount; k++ )
            image[k] = new ImageIcon( getImage( getDocumentBase( ), getParameter( "file"+k ) ) );
        // build a new JPanel with GridLayout
        panel = new JPanel( new GridLayout( 2, 5 ) );
        // add images to the panel
        for ( int k=0; k<paramCount; k++ )
            panel.add( new JLabel( image[k] ) );
        // add panel to me (this applet object)
        add( panel );
    }  // end init method
}  // end class
Roman C
  • 49,761
  • 33
  • 66
  • 176

1 Answers1

1

Are you passing in parameters to the applet via AppletViewer? I doubt you are.

In Eclipse you would do this via the Run menu Run Configurations... sub menu item, then the Parameters tab.

enter image description here

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373