OZONE Asylum
Forums
OZONE
Java: Instantiate classes by name from a file
This page's ID:
28631
Search
QuickChanges
Forums
FAQ
Archives
Register
Edit Post
Who can edit a post?
The poster and administrators may edit a post. The poster can only edit it for a short while after the initial post.
Your User Name:
Your Password:
Login Options:
Remember Me On This Computer
Your Text:
Insert Slimies »
Insert UBB Code »
Close
Last Tag
|
All Tags
UBB Help
The solution that actually appears to have worked (so far, because I haven't yet tested it completely) is a combination of the two. [code] Class currClass; Modules currModule; try { currClass = Class.forName("ClassNameFromFile"); currModule = (Modules)currClass.newInstance(); } catch (ClassNotFoundException e) { System.out.println("Could not find module"); e.printStackTrace(); } catch (InstantiationException e) { System.out.println("Could not create a module instance"); e.printStackTrace(); } catch (IllegalAccessException e) { System.out.println("Could not access named module"); e.printStackTrace(); } [/code] Of course, for this to work, you have to import java.lang.relfect.*; but, eh, that's just a line of code, not hard to do. Thanks for all your help. [url=http://sunday.yarinareth.net][img]http://members.ii.net/~skaarjj/tempus.gif[/img][/url] Justice 4 [url=http://www.justice4pat.com]Pat Richard[/url] [small](Edited by [url=http://www.ozoneasylum.com/user/157]Skaarjj[/url] on 11-12-2006 00:39)[/small]
Loading...
Options:
Enable Slimies
Enable Linkwords
« Backwards
—
Onwards »