0

I'm working on a basic applet and I'm getting the following error when I compile in Eclipse:

java.lang.NullPointerException
at java.applet.Applet.getParameter(Applet.java:191)
at com.putable.clickaid.ClickAid.<init>(ClickAid.java:18)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at java.lang.Class.newInstance(Class.java:379)
at sun.applet.AppletPanel.createApplet(AppletPanel.java:795)
at sun.applet.AppletPanel.runLoader(AppletPanel.java:724)
at sun.applet.AppletPanel.run(AppletPanel.java:380)
at java.lang.Thread.run(Thread.java:745)

When I try to run it with appletviewer, I get a blank window and a notification that the applet hasn't been initialized. (I get the empty window on Eclipse, too.) If I try to compile the files via the command line, I get repeated "cannot find symbol" errors for the other classes in the package. (I'm not getting anything like this in Eclipse.) Here's the first part of the main class, along with part of the constructor (I'll post more code if needed):

public class ClickAid extends Applet implements ActionListener {
    int rows;
    int columns;
    ActiveSquare[][] buttons = new ActiveSquare[rows][columns];
    int appxMax = 0;
    int appyMax = 0;
    private static final long serialVersionUID = 1L;


public ClickAid() { 
    if (getParameter("ROWS") == null) {rows = 4;}
    rows = Integer.parseInt(getParameter("ROWS"));
    columns = 6;
    if (getParameter("COLUMNS") == null) {columns = 6;}
    else {columns = Integer.parseInt(getParameter("COLUMNS"));}
...

I know that seems like a lot of questions in one, but I'm assuming at least some of them are related. My main concern is the issue with fetching the parameters - I set them up via run configurations, and I haven't been able to find any clues as to why it's not working.

r.ree
  • 35
  • 5
  • 3
    `if (getParameter("ROWS") == null) {rows = 4;}`. You acknowledge that it can be null. `Integer.parseInt(getParameter("ROWS"))`. But then you are surprised when it causes `NullPointerException`. Did you forget to write `else`? If you formatted your `if` statements correctly, you would have seen that. It's one of the reasons there are formatting guidelines. The other is readability, and I had to look many times to see that you had `else` on COLUMNS, but not on ROWS. Oh, and the exception told you exactly what line the error was on, so why was it you needed our help? – Andreas Nov 08 '15 at 03:10
  • 1
    No ... you are not getting it when you compile. You are getting it when you run. – Stephen C Nov 08 '15 at 03:32

0 Answers0