R
Rick
I am using a custom ClassLoader to load a class. The class loads fine,
but the instantiation with Class's newInstance() method returns a
null.
Code snippet:
TestClassLoader loader = new TestClassLoader(dirName);
System.out.println("\n\ntest = " + test + "\n");
Class c = Class.forName("tests.Kiv7Test",true,loader);
Object t = c.newInstance(); //OBJECT t is NULL!!!
System.out.println("Class loaded: " + c.getName () + " Object:" + t +
" isInstance: " + c.isInstance (t));
Output:
test = tests.Kiv7Test
default Kiv7Test
Class loaded: tests.Kiv7Test Object:null(tests.Kiv7Test) isInstance:
true
The "default Kiv7Test" output is a simple println() in the Kiv7Test
no-arg constructor, so we know the Kiv7Test was loaded, instantiated,
and ran properly.
Any advice on how to overcome this situation (and an explanation of
what I'm doing wrong) would be appreciated.
TIA!
-Rick
but the instantiation with Class's newInstance() method returns a
null.
Code snippet:
TestClassLoader loader = new TestClassLoader(dirName);
System.out.println("\n\ntest = " + test + "\n");
Class c = Class.forName("tests.Kiv7Test",true,loader);
Object t = c.newInstance(); //OBJECT t is NULL!!!
System.out.println("Class loaded: " + c.getName () + " Object:" + t +
" isInstance: " + c.isInstance (t));
Output:
test = tests.Kiv7Test
default Kiv7Test
Class loaded: tests.Kiv7Test Object:null(tests.Kiv7Test) isInstance:
true
The "default Kiv7Test" output is a simple println() in the Kiv7Test
no-arg constructor, so we know the Kiv7Test was loaded, instantiated,
and ran properly.
Any advice on how to overcome this situation (and an explanation of
what I'm doing wrong) would be appreciated.
TIA!
-Rick