Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2005

Tip: Looking for answers? Try searching our database.

Getting class using (Class.forname()) and casting the instance

Thread view: 
Madni - 19 Dec 2005 14:59 GMT
Dear All,

This chunk of code is working well in my servlet

     Class myclass = Class.forName(strMgrApp);
    //where strMgrApp actually holds the class TagImportExportMgrApp
     TagImportExportMgrApp ob; // any class name
    ob  = (TagImportExportMgrApp) myclass.newInstance();
    oImportExportMgr = (IImportExportMgr) ob;
//IImportExportMgr is interface which TagImportExportMgrApp implements

No runtime error is returned and i can access methods using object
"oImportExportMgr"

But !!!!!!!!!!!!!!!!!!!!!!!!!

whats the problem with this line below :

oImportExportMgr =(IImportExportMgr)
Class.forName(strMgrName).newInstance();

why it generates a runtime error stating :

java.lang.IllegalAccessError: tried to access class
WES.GenericComponents.UploadFile.IImportExportMgr from class
WES.GenericComponents.UploadFile.UploadManager

Any suggestion would be highly obliged

Regards ,

Madni
ricky.clarkson@gmail.com - 19 Dec 2005 19:00 GMT
> java.lang.IllegalAccessError: tried to access class
> WES.GenericComponents.UploadFile.IImportExportMgr from class
> WES.GenericComponents.UploadFile.UploadManager

Try posting a complete test case that we can compile and run, or
examine the API docs for IllegalAccessError:
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/IllegalAccessError.html

A rebuild will probably fix this.

Of course, you probably didn't paste the exception output properly, so
you probably want to really look at:
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/IllegalAccessException.html

Note that reflection is generally used to pretend that Java is a
dynamically-typed language.  The only valid use I know is for plugins
that are not known about at the time the application is started.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.