Win a copy of AWS Security this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Applet-to-Applet, ClassCastException

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Joe Meade
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic