File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
O. Ziggy
Ranch Hand
Posts: 430
Android Debian VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
O. Ziggy
Ranch Hand
Posts: 430
Android Debian VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic