• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

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

 
Ranch Hand
Posts: 430
Android VI Editor Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Who knew that furniture could be so violent? Put this tiny ad out there to see what happens:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic