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

Passing Parameters - I'm ready to scream!!!

1 view
Skip to first unread message

Marty Hall

unread,
Oct 29, 1996, 3:00:00 AM10/29/96
to

mmc9...@dmu.ac.uk (David McGlashan) writes:

>
> I'm trying to pass parameters to a Java program via
> the <applet> tag in an HTML document, but the
> program falls down when I try and I am unable to
> locate any fault in either the Java or the HTML.
[...]
> This is the Java source for recieving the parameters:
> (The line numbers do NOT appear in the program)
> 32: int bodies = Integer.parseInt(getParameter("bodies")) ;
> 33: int display = Integer.parseInt(getParameter("display")) ;
> 34: double scale = Double.valueOf(getParameter("scale")).doubleValue() ;

MHSDS (Marty's Highly Sophisticated Debugging Strategy (TM)) says
"find out what expression is causing the error, and then it is usually
obvious". Thus, I suggest you first read the params in as Strings, and
print out their values before passing them to Integer.parseInt,
etc. This will help you find if the getParameter is failing (perhaps
incorrect case) or it is something else.
- Marty

Java Programming Resources: <http://www.apl.jhu.edu/~hall/java/>

David McGlashan

unread,
Oct 29, 1996, 3:00:00 AM10/29/96
to

I'm trying to pass parameters to a Java program via
the <applet> tag in an HTML document, but the
program falls down when I try and I am unable to
locate any fault in either the Java or the HTML.

This is what appears in the status line:
Applet can't start: exception: java.lang.NullPointerException

This is what appears in the Java Console:
# Applet exception: exception: java.lang.NullPointerException
java.lang.NullPointerException
at java.applet.Applet.getParameter(Applet.java:74)
at mbi.<init>(mbi.java:32)
at netscape.applet.EmbeddedAppletFrame.run(EmbeddedAppletFrame.java:278)
at java.lang.Thread.run(Thread.java:296)



This is the Java source for recieving the parameters:
(The line numbers do NOT appear in the program)
32: int bodies = Integer.parseInt(getParameter("bodies")) ;
33: int display = Integer.parseInt(getParameter("display")) ;
34: double scale = Double.valueOf(getParameter("scale")).doubleValue() ;

This is the HTML that starts the applet
<applet code="mbi" width=500 height=500 align=left>
<param name=bodies value=4>
<param name=display value=1>
<param name=scale value=8e7>
</applet>

If I interpret the Java Console information correctly
then there is a fault in line 32 of my program, which
is the line that passes the bodies integer. If you
try to pass a parameter that does not exist then the
interpreter returns a NULL, but the bodies parameter
DOES exist and hence I do not understand what I am
doing wrong.

Can anybody help?

The program does run if I define these values internally
and perform no parameter passing, but that kind of
defeats the object.

Robert Lynch

unread,
Oct 29, 1996, 3:00:00 AM10/29/96
to David McGlashan

Your code seems to work for me; here's mbi.html:

[user@ravel mbi]$ more mbi.html
<html>
<body>


<applet code="mbi" width=500 height=500 align=left>
<param name=bodies value=4>
<param name=display value=1>
<param name=scale value=8e7>
</applet>

</body>
</html>

and mbi.java:

[user@ravel mbi]$ more mbi.java
public class mbi extends java.applet.Applet {

public void init() {


int bodies = Integer.parseInt(getParameter("bodies")) ;

int display = Integer.parseInt(getParameter("display")) ;

double scale =
Double.valueOf(getParameter("scale")).doubleValue() ;

System.out.println("Values are:\n" + "bodies= " + bodies + "\n"+
"displa
y=" +display + "\n" + "scale= " + scale + "\n");
}
}

running the applet after compilation, here is the Java console display:

Values are:
bodies= 4
display=1
scale= 8e+07

Hope this helps track down your problem...

Bob L.
--
Robert Lynch-Berkeley CA USA-r...@best.com
--

Jakob Hummes

unread,
Oct 30, 1996, 3:00:00 AM10/30/96
to David McGlashan

David McGlashan wrote:

> This is the HTML that starts the applet
> <applet code="mbi" width=500 height=500 align=left>
> <param name=bodies value=4>
> <param name=display value=1>
> <param name=scale value=8e7>
> </applet>

Just a thought. I define parameter passing in all my HTML pages with
double-quates, i.e.:


<applet code="mbi" width=500 height=500 align=left>
<param name="bodies" value="4">
<param name="display" value="1">
<param name="scale" value="8e7">
</applet>

Hope, that helps,
- Jakob
--
WORK:
Jakob Hummes
EURECOM
2229, route des Cretes
B.P. 193
06904 Sophia Antipolis Cedex
FRANCE
Tel: (+33) (0)4 93 00 26 70 WWW: http://www.eurecom.fr/~hummes
Fax: (+33) (0)4 93 00 26 27

0 new messages