the various examples and they are not working for the application I am
working on however when I make my own
simple sample it works just fine.
This is the error I get when trying it in the project:
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
seem to work however, I have tried the call in many other methods and
also calling it from a seperate class.
String s ="initial";
s = getParameter("asdf");
<param name="asdf" value="hi">
Thanks.
If your simple example works 'just fine', what is your question?
--
Andrew Thompson
http://www.athompson.info/andrew/
Message posted via http://www.javakb.com
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
It is obvious after viewing the replies I wasn't completely clear and
that is probably because
I don't know much about the general workings of a Java applet at this
point well enough to
explain what I am trying to do.
Yes apparently I didn't ask a question my apologies, I suppose in
hindsight my question was
what could be causing an issue with get parameters when it does work
with a simple example?
"A constructor with no arguments is
generally referred to as a "no-args constructor". "
Generally? All books that I have read have almost always called it a
default constructor but thank you
for the extra info.
(applet)
>what could be causing an issue with get parameters when it does work
>with a simple example?
The HTML is the most likely culprit. Is it validated?
What is the URL of the HTML/applet?
Had you considered web start for launching this applet?
E.G. <http://www.physci.org/jws/#jtest> (applet, but no
parameters specified).
--
Andrew Thompson
http://www.athompson.info/andrew/
Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-gui/200705/1
I have found a way to get it to work (although I'm sure its less than
great):
// CLASS TO HANDLE PARAMS:
public class MAParam extends JApplet {
public static String myStatic = "init static";
public void init()
{
myStatic = getParameter("count");
}
}
// HTML:
<html>
<body>
<applet code="MAParam.class" width="0" height="0">
<param name="count" value=2 />
</applet>
<applet code="ClassIDidntWrite.class" width="800" height="550">
</applet>
</body>
</html>
// CLASS: ClassIDidntWrite
private static String PARAM;
public ClassIDidntWrite() {
PARAM = MAParam.myStatic;
System.out.println("PARAM IS: " + PARAM);
System.out.println("MyStatic IS: " + MAParam.myStatic);
...