Richard said:
I'm calling my Applet like this 'var chan =
document.getElementById("myApplet")' and inside my class definition that
extends applet I have a variable "pipe" that is an instance of the
Tier3Socket class and I want JavaScript to be able to invoke methods in
"pipe" and I am getting a null pointer error if I try and say "byte_count
= chan.pipe.readMessage(2)".
a) Can I only call public methods at the Applet Class level from JS? (No
big deal)
b) If I say "var getClass = chan.pipe" can I then invoke getClass.xxx()
methods?
c) Is it just that I haven't said "public" when I declared "Tier3Socket
pipe;"
I don't really know, I'm afraid. If the Live Connect guide I'm looking at is
at all relevant (I don't know for sure that you are usng Live Connect, or even
if LC still exists !), then the answer to (b) /should/ be "yes". Other than
that, I'm guessing, but I wouldn't be at all surprised if the answer to all
three questions was "yes" -- but that's only because that's how I'd have
designed it, not because I know how the JS integration actually works.
(BTW (c) confused me a little, I'm assuming that you have just choosen
"getClass" as the arbitrary name for a variable, you're not attempting to call
the pipe object's getClass() method.)
It might sound silly, but is there any chance that your applet's "pipe" field
actually /is/ null ? It's worth adding some tracing or something just to
double check...
(What is the default anyway?)
The default for classes, fields, and methods is so-called "package private",
which means that the class, field, or method isn't supposed to be visible from
outside its own package -- JS doesn't /have/ to honour that (it could just
ignore it, since Java protections don't apply if you are using JNI), but I'd
guess that the designers would attempt to mimic Java semantics as far as they
could and so they won't expose non-public members.
Everything I'm looking at (control panel, console etc) says "Sun
Microsystems Inc. Java HotSpot Client VM 1.6.0-b105"; short of running
Microsofts MSJVM remover tool, I don't know what else to do.
Sounds good. If you want to double-check, there's a system property
("java.vendor") you can check from your applet code to see the maker of the JVM
you are actually running in (as opposed to the one that's installed and you
/hope/ you are running in ;-). There's an example here:
http://www.javaworld.com/javatips/jw-javatip53.html
One other thing. I have just found this on the Web. It's clearly long out of
date, but it may still be relevant or even correct.
http://www.unix.org.ua/orelly/web/jscript/ch19_07.html
If it is then that may explain your problems too. (Easy way to check: run your
applet under FireFox and see what changes...)
-- chris