Creating a class instance using Class.forName() from a different directory
807606Mar 15 2007 — edited Mar 15 2007Hi,
I have a Class Browser program. Currently, the way it works is that I browse to the directory where my source code is, then I highlight the Java/Class file in that source code, and the browser(JTree) gets populated with the Method names in those classes.
The problem I am facing is that I am able to get Method names only for classes within the Main class directory of this code. If I try to browse to any other directory in my computer I am able to obtain the Class names but my functionality of getting methods from that class are not working, I get "Class not found" exception on line 3.
Here is a snippet of the code I am using:
1. String className = objectClicked.getName().toString();
2. Class myClass;
3. myClass = Class.forName(className); //Creates an instance of the selected Class
4. Method[] myMethods = myClass.getDeclaredMethods();
I am able to get this to work as long as I am only selecting source code in the same directory as the current code.
Could anyone help me with this? I need to be able to create a class reflection to get its Method list outside of my source directory.
Thanks !