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
精彩评论