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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

question on dynamic class loading

Status
Not open for further replies.

zhanghong920

Programmer
Nov 15, 2002
27
0
0
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 = ... //it's: abb.dlt.oai.client.F
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
 
The exception says that F has the interface G as super class. This is clearly not the case now, but maybe it was before?

The Javadoc on java.lang.IncompatibleClassChangeError suggests, that you might need to recompile some of the classes.


Lars
 
You're right! nothing wrong after I recompile them. Thanks a lot.

zhanghong920
 
>> Object obj = Class.forName(className).newInstance();
G obj = (G) obj;

is't My eyes, or "obj" is declared twice above? That could be ur problemo. [afro]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top