on 10-23-2006 2:34 PM
Hi guys,
I want to directly point a java class in a main method and build a new instance of the called class.
In order to understand the class I use the following code:
_____________
String jMapClass = args[0];
System.out.println(Class.forName(jMapClass));
___________________
nevertheless I get the following error:
java.lang.ClassNotFoundException
I want to give class as input to the main.
So i add the class to the project and i give it with fully qualified name ad argument to the main.
for example package is
/javamappingtester/javamappingtester
path of the class to load is
/javamappingtester/javamappingtester/ParsingJAXPOAL.java(input of the arguments without ".java")
path of the main is
/javamappingtester/javamappingtester/Tester.java
what is wrong?
any suggestion?
thanks
regards,
Giamma
The issue was just some helper class not connected in the class path
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Giamma,
I tried creating the same code that you want, and it worked fine. I think the following code should help you, it creates a class object given the type of object name as a string arguement.
Object object = null;
Class classDefinition;
try {
classDefinition = Class.forName("com.guru.utils.TestClass");
object = classDefinition.<b>newInstance</b>();
System.out.println(object);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Best regards,
Guru.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
91 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.