Meaningless Drivel is fun!*
The moose likes Java in General and the fly likes Using class.forname().newInstance() and Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Using class.forname().newInstance() and "com.sun.jdi.InvocationException occurred invoking method" e" Watch "Using class.forname().newInstance() and "com.sun.jdi.InvocationException occurred invoking method" e" New topic

Using class.forname().newInstance() and "com.sun.jdi.InvocationException occurred invoking method" e

O. Ziggy
Ranch Hand

Joined: Oct 02, 2005
Posts: 430

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.

On initialisation, the above classnames are put in a vector. The vector is then accessed and each class is initialised as shown below

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 extend the GenericParser abstract class.
The GenericParser abstract class implements the ParserInterface.
None of the parsers have a constructor so default constructors will be used.

When i run the above it generates an exception shown below

Any ideas why this is happening and could the structure of the packaging be a cause for this?

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.
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24183

Are you sure that the interfaces and abstract classes aren't included in the list? If you broke that long line into several, you could print out the name of each class before attempting to process it; that's tell you which one was failing.

[Jess in Action][AskingGoodQuestions]
O. Ziggy
Ranch Hand

Joined: Oct 02, 2005
Posts: 430

These classes are not loaded

They are just in the same package as the parser classes. They are not loaded as they are not in the list of classes to be loaded in the properties file.

The classes that dont get loaded are those in the net.package.* package.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Using class.forname().newInstance() and "com.sun.jdi.InvocationException occurred invoking method" e
Similar Threads
InvocationException from Java Debug Interface in Bodgitt & Scarper 2.2.3
Creating subclass of abstract class at runtime
Database Connection
Problem facing with HibernateTemplate
OJB Reference Descriptor 1:0 relationship? Should I set auto-retrieve to false?