Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic instantiate

Status
Not open for further replies.

zhanghong920

Programmer
Nov 15, 2002
27
US
Hi all,

I'm trying to read the class name from a configure file, and then create an instant of it. The related classes are:

//G:
public interface G{
public void setProperties(Properties p);
public void setDBConnect();
}

//F:
public class F extends SF implements G{
//implement setProperties(), setDBConnect(), and other overriding methods defined in the superclass SF.
}

//A:
public class A{
public static void main(..){
String className = ... //get from the configure file
Properties p = ... //build according to the configuring

Object obj = Class.forName(className).newInstance();
G obj = (G) obj;
obj.setProperties(p);
}
}

Some other unrelated lines are omitted here. The problem is: it's fine in compiling. But when I run: "java A",there's an error message as below:

Exception in thread "main" java.lang.IncompatibleClassChangeError: class abb.dlt.oai.client.F has interface abb.dlt.oai.client.G as super class
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:130)
at abb.dlt.oai.client.A.main(A.java:63)

Anything I missed? Thanks a lot,

Zhanghong920
 
Sorry I forgot to mention that:
the content of "className" in the main() of A is:
"abb.dlt.oai.client.F"

Thanks for any help.

Zhanghong920
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top