Bah, silly Applets!
Solved!
Bah. It was something reasonably obvious. By calling getParameter in the constructor, I wasn't waiting for the init() method to be called, where presumably all the setting up gets done. So it just wasn't ready for me to start asking it stuff.
Thanks for all your suggestions.
I've not done a whole lot of Applet programming, and I'm a little stumped by an exception I'm getting in my code. Was hoping someone might be able to give me a hand. It has to do with getting parameters from the html file loading the applet. Maybe I'm just being dense.
First off, my applet tag looks like this:
<APPLET CODE="org.morgoth.pmath370.StartPanel.cl ass" ARCHIVE="FractalMusic.jar"
WIDTH=200 HEIGHT=40>
<PARAM NAME=playerClass VALUE="org.morgoth.pmath370.RandomPlayer" >
</APPLET>
The pertinent Java is fairly straightforward:
public StartPanel() {
String playerClass = getParameter("playerClass");
...
}
Where "StartPanel" is my class that extends Applet. Everything else about my applet works as it should (if I catch the exception and set playerClass manually, things run smoothly), but the getParameter() call results in:
java.lang.NullPointerException
at java.applet.Applet.getParameter(Applet.j ava:158)
at org.morgoth.pmath370.StartPanel.<init>(S tartPanel.java:32)
at sun.reflect.NativeConstructorAccessorImp l.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImp l.newInstance(NativeConstructorAccessorI mpl.java:39)
at sun.reflect.DelegatingConstructorAccesso rImpl.newInstance(DelegatingConstructorA ccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstanc e(Constructor.java:274)
at java.lang.Class.newInstance0(Class.java:3 06)
at java.lang.Class.newInstance(Class.java:2 59)
at sun.applet.AppletPanel.createApplet(Appl etPanel.java:566)
at sun.applet.AppletPanel.runLoader(AppletP anel.java:495)
at sun.applet.AppletPanel.run(AppletPanel.j ava:292)
at java.lang.Thread.run(Thread.java:536)
I'm at a loss to explain why I'm getting a NullPointerException. If I specified the parameter improperly, I should be getting null as a return value, not a NPE.
I've been at this a while, so maybe I'm getting tired and there's an obvious problem. Anyone know what it might be?
Update: The part in Applet throwing the exception is:
public String getParameter(String name) {
return stub.getParameter(name);
}
It seems stub is null. Hmm.
Bah. It was something reasonably obvious. By calling getParameter in the constructor, I wasn't waiting for the init() method to be called, where presumably all the setting up gets done. So it just wasn't ready for me to start asking it stuff.
Thanks for all your suggestions.
I've not done a whole lot of Applet programming, and I'm a little stumped by an exception I'm getting in my code. Was hoping someone might be able to give me a hand. It has to do with getting parameters from the html file loading the applet. Maybe I'm just being dense.
First off, my applet tag looks like this:
<APPLET CODE="org.morgoth.pmath370.StartPanel.cl
WIDTH=200 HEIGHT=40>
<PARAM NAME=playerClass VALUE="org.morgoth.pmath370.RandomPlayer"
</APPLET>
The pertinent Java is fairly straightforward:
public StartPanel() {
String playerClass = getParameter("playerClass");
...
}
Where "StartPanel" is my class that extends Applet. Everything else about my applet works as it should (if I catch the exception and set playerClass manually, things run smoothly), but the getParameter() call results in:
java.lang.NullPointerException
at java.applet.Applet.getParameter(Applet.j
at org.morgoth.pmath370.StartPanel.<init>(S
at sun.reflect.NativeConstructorAccessorImp
at sun.reflect.NativeConstructorAccessorImp
at sun.reflect.DelegatingConstructorAccesso
at java.lang.reflect.Constructor.newInstanc
at java.lang.Class.newInstance0(Class.java:3
at java.lang.Class.newInstance(Class.java:2
at sun.applet.AppletPanel.createApplet(Appl
at sun.applet.AppletPanel.runLoader(AppletP
at sun.applet.AppletPanel.run(AppletPanel.j
at java.lang.Thread.run(Thread.java:536)
I'm at a loss to explain why I'm getting a NullPointerException. If I specified the parameter improperly, I should be getting null as a return value, not a NPE.
I've been at this a while, so maybe I'm getting tired and there's an obvious problem. Anyone know what it might be?
Update: The part in Applet throwing the exception is:
public String getParameter(String name) {
return stub.getParameter(name);
}
It seems stub is null. Hmm.
