Re: japplet param



ryanoasis wrote:

java.lang.NullPointerException
at java.applet.Applet.getParameter(Unknown Source)

I have read that the getParameter call should be in init and also in
the default constructor. This doesnt

Where did you read that?[1]

The constructor must have completed before getParameter will work.

getParameter just forwards to the AppletStub (look at the source). Because your subclass of Applet calls the no-args Applet constructor (either implicitly or explicitly), there is no (reasonable) way the applet container can set the stub before your constructors have completed.

You should be able to call getParameter in the init method.

[1] As a point of pedantry a default constructor is technically a synthetic constructor provided by the compiler if there are no constructors is the class' source. A constructor with no arguments is generally referred to as a "no-args constructor".

Tom Hawtin
.



Relevant Pages

  • Re: Why do applets need init()
    ... > Why do applets need init()? ... Wouldn't instance initialization (I think ... The functionalities of constructor and the initmethod are separated, ... other applet methods too: getCodeBase, getDocumentBase, ...
    (comp.lang.java.help)
  • Re: simple sound problem
    ... > | public class Class_Sound extends JApplet{ ... The base class Applet has a single constructor that takes no arguments ... inline field initializaters) are moved ...
    (comp.lang.java.programmer)
  • Re: Reflection problem
    ... > I'm trying to write an application which communicates with a remote ... Normally an applet is loaded from the server system which ... > application rather than an applet. ... It then calls the constructor: ...
    (comp.lang.java.programmer)
  • Re: Convenience constructors and non-final setters
    ... comfort severely (ok, I guess that argument doesn't count for OO-purists), ... init() method which would have been called before setSeed. ... constructor runs, initruns, setSeedruns, and the subclass ... In my opinion they should have made Random abstract, ...
    (comp.lang.java.programmer)
  • Re: Have a constructer with the paramters sent through an applet store them as global variables
    ... I see the variables even before the frame is loaded. ... This is the applet ... And this is the constructor of the Frame ... Can anyone please tell me how to make the Url and HTTP global variables ...
    (comp.lang.java.help)