[4978] in java-interest
Creating new objects given a class name
daemon@ATHENA.MIT.EDU (Gregg Helt)
Wed Jan 24 23:09:17 1996
Date: Wed, 24 Jan 1996 18:14:09 -0800 (PST)
From: Gregg Helt <gregg@fruitfly.berkeley.edu>
To: java-interest@java.sun.com
In-Reply-To: <31068E2E.744A@impltd.com>
I'm trying to take a String with the name of a class, and instantiate
objects of that class. I've been trying to do this with Class methods:
Class class_type;
class_type = Class.forName("class_name");
...
Object obj;
obj = class_type.newInstance();
This compiles OK, but running it gives a "java.lang.NoSuchMethodError" on
that last line. And even if it did run, I'm not sure what to do with the
resulting object -- how do I call a constructor for obj?
Is there another way to do this? Am I not _supposed_ to be able to do this?
thanks,
gregg
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com