| View previous topic :: View next topic |
| Author |
Message |
ryanoasis Guest
|
Posted: Mon Apr 23, 2007 10:31 pm Post subject: japplet param |
|
|
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. |
|
| Back to top |
|
 |
Andrew Thompson Guest
|
Posted: Tue Apr 24, 2007 3:58 am Post subject: Re: japplet param |
|
|
ryanoasis wrote:
...
| Quote: | 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 |
|
| Back to top |
|
 |
Tom Hawtin Guest
|
Posted: Tue Apr 24, 2007 6:26 am Post subject: Re: japplet param |
|
|
ryanoasis wrote:
| Quote: |
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 |
|
| Back to top |
|
 |
ryanoasis Guest
|
Posted: Wed May 09, 2007 9:24 pm Post subject: Re: japplet param |
|
|
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. |
|
| Back to top |
|
 |
Andrew Thompson Guest
|
Posted: Thu May 10, 2007 3:45 am Post subject: Re: japplet param |
|
|
ryanoasis wrote:
(applet)
| Quote: | 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 |
|
| Back to top |
|
 |
ryanoasis Guest
|
Posted: Thu May 10, 2007 10:25 pm Post subject: Re: japplet param |
|
|
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);
... |
|
| Back to top |
|
 |
|