0

我一直在开发 OpenOffice Writer 扩展。目前,我需要检索当前的文档对象。以下应将当前组件作为 Writer 文档返回。

XMultiComponentFactory factory = context.getServiceManager();
XDesktop desktop = (XDesktop) factory.createInstanceWithContext("com.sun.star.frame.Desktop", context);
XTextDocument document = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, desktop.getCurrentComponent());

return document;

我的问题发生在第二行运行时。抛出以下异常:

java.lang.ClassCastException: com.sun.proxy.$Proxy0 cannot be cast to com.sun.star.frame.XDesktop

为什么createInstanceWithContext返回的东西不符合请求的接口?有没有办法解决它?

4

1 回答 1

1

查看此处的文档,获取界面有两个步骤:

          Object desktop = xRemoteServiceManager.createInstanceWithContext (
              "com.sun.star.frame.Desktop", xRemoteContext);
          XDesktop xDesktop = (XDesktop)UnoRuntime.queryInterface(XDesktop.class, desktop);
于 2013-08-06T15:36:07.067 回答