Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

japplet param

0 views
Skip to first unread message

ryanoasis

unread,
Apr 23, 2007, 1:31:36 PM4/23/07
to
I am new to Java applets and therefore japplets as well.
I am working on a project that we want to get the params from the page
the applet tag is on. I have looked at

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.

Andrew Thompson

unread,
Apr 23, 2007, 6:58:36 PM4/23/07
to
ryanoasis wrote:
..

>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.

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

Tom Hawtin

unread,
Apr 23, 2007, 9:26:55 PM4/23/07
to
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

ryanoasis

unread,
May 9, 2007, 12:24:52 PM5/9/07
to
Sorry I meant I read that it should be in the default constructor OR
the init method.

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.

Andrew Thompson

unread,
May 9, 2007, 6:45:34 PM5/9/07
to
ryanoasis wrote:

(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).

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-gui/200705/1

ryanoasis

unread,
May 10, 2007, 1:25:54 PM5/10/07
to
I will look into that.

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);
...

0 new messages