I am using class.forname to create a new instance of class.The classname comes from a properties.
Lets say i have several classes in two packages.
com.package.Parser1
com.package.Parser2
com.package.Parser3
net.package.parser4
net.package.parser5
net.package.parser6
The following classes also exist in the above packages (This are not instantiated)
com.package.ParserLoader
com.package.ParserInterface
net.package.GenericParser
On initialisation, the above parser are put in a vector. The vector is then accessed and each class is initialised using its class name as shown below
while (tokens.hasMoreTokens())
parsers.addElement(
Class.forName((String) tokens.nextToken()).newInstance());
}catch(Exception e){
e.printStackTrace();
}
The code above is in the class ParserLoader which is in the same package as parsers 1,2,3.
Parsers 1, 2 and 3 all implement the ParserInterface. Parsers 4,5 and 6 all extends the abtract GenericParser. The GenericParser implements the ParserInterface.
When i run the above it generates an exception shown below
com.sun.jdi.InvocationException occurred invoking method
Any ideas why this is happening?
Another problem i am having is i cant see any stack trace. There is no stacktrace! I only see that error in eclipse when i debug the application and look at the content of the parsers vector. The vector should contain references to the parser objects. The parsers in com.package.* package are fine but it is not creating instances of any parser in the net.package.* package.
I think you'll get this exception if your constructors are messed up or something else is broken while creating the parsers. Check this out: http://download.oracle.com/javase/6/docs/jdk/api/jpda/jdi/com/sun/jdi/InvocationException.html, and try to get more info out of your exception.