开发者

Unable to use Com4j to work with QC object model

Situation: I got successful in connecting to my QC with com4j and java

java code:

ITDConnection itdc= ClassFactory.createTDConnection();
System.out.println(itdc.connected());
itdc.initConnectionEx(url);
System.out.println(itdc.connected());
itdc.connectProjectEx(domainName, projectName, userName, password);

// project name
System.out.println(itdc.projectName());

But i can't do any cast from object

ITestFactory itf=开发者_JS百科(ITestFactory) itdc.testFactory();

this fail with Exception in thread "main" java.lang.ClassCastException: $Proxy11 cannot be cast to test.ota.ITestFactory

Please help


You can't cast COM objects directly. Use the object's queryInterface method instead:

TargetType castObject = myObject.queryInterface(TargetType.class);

See Casting and QueryInterface in http://com4j.java.net/runtime-semantics.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜