I've got an applet talking to another applet on the same web page, with the code in the same directory. I retrieve an Enumeration of all the applets on the page and need to call methods on it if it is of a certain type. The problem is that I've been unable to cast the applet to the appropriate subclass. Consider:
Incidentally, someApplet.getName() does not return the HTML parameter set on the web page, as the javadocs suggest. Instead, it returns things like panel0, panel1, panel2. Any ideas as to why the Class Name would be correct but a cast would fail? I didn't write foo.Bar, might there be something internal that is giving me trouble? TIA, Joe
Hi Joe Yes. It is possible that you get the class name correct but instanceof fails. The reason could be if those two classes are loaded by different class loaders then they wouldn't be compatible hence instanceof fails. Try to know if the class loaders are different or not via, System.out.println("First applet's class loader:"+this.getClass().getClassLoader().toString()); System.out.println("Second applet's class loader:"+someApplet.getClass().getClassLoader().toString()); If they look same then I am not sure what could be the issue. I assume that both the applets are loaded from the same host. Regards Maulin
posted 16 years ago
Originally posted by Maulin Vasavada:
... The reason could be if those two classes are loaded by different class loaders then they wouldn't be compatible hence instanceof fails. ...
Maulin, Thanks for the tip. It got me heading in the right direction. There was a problem in the ARCHIVE parameter of my applet tag. Once I made foo.Bar the first class in the list, it worked like a charm! Originally, a parent class of foo.Bar was first. Thanks again. Joe
If you are using a wood chipper, you are doing it wrong. Even on this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!