The Artima Developer Community
Sponsored Link

Dynamic class loading in Applets

Advertisement

Advertisement

This page contains an archived post to the Design Forum (formerly called the Flexible Java Forum) made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Dynamic class loading in Applets

Posted by Patrik Mihailescu on 22 Dec 1998, 3:24 PM

I read the article and got the examples working fairly easily, in
a java application. However when l tried to convert the examples
to an applet, l ran into quite a few problems.

I am using your RodentClassLoader class, including your Cat, Rodent and Mouse classes. When l use your java application and type:
java Cat Mouse
I get a message "Mouse scurrying", which indicates that the java application is dynamically loading the Mouse class.

However when a convert the Cat class into a applet, l get the following error message:
java.lang.ClassCastException: Mouse.

I believe that the Mouse class is being loaded correctly (as l recieve no error messages), but when l try the following statement, l receive the above error message.

Rodent myToy = (Rodent) c.newInstance();

I am using the Java 2 development kit and my applet has the right to create a classloader and read files, so l don't think its a problem with security restrictions.

My applet is in a jar file, which includes the Rodent class. The applet dynamically loads the Mouse class from another directory (which includes the Rodent class), but fails to cast the retrieved class to the Rodent class.

I hope that you could shed some light on how l may solve this problem.

Thank you

Patrik Mihailescu.



Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us