1

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=(ITestFactory) itdc.testFactory();

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

Please help

Jay D
  • 3,263
  • 4
  • 32
  • 48
Rajiv
  • 11
  • 2

1 Answers1

4

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

Jay D
  • 3,263
  • 4
  • 32
  • 48
user702148
  • 41
  • 1