Apache OpenOffice (AOO) Bugzilla – Issue 102348
XTextRangeCompare throws IllegalArgumentException when compairing two XTextRange of two XTextTable
Last modified: 2017-05-20 11:17:45 UTC
Hi, gmane.comp.openoffice.devel.general discussion: "Compairing text content positions with each other" Exact Problem: XTextRangeCompare throws following exception when compairing two XTextRanges of XTables: >Exception occurred in target VM: com.sun.star.lang.IllegalArgumentException: at com.sun.star.bridges.jni_uno.JNI_proxy.dispatch_call(Native Method) at com.sun.star.bridges.jni_uno.JNI_proxy.invoke(JNI_proxy.java:178) at $Proxy35.compareRegionStarts(Unknown Source) at ast.structure.ElementController.checkTextTable(ElementController.java:939) at ast.structure.ElementController.analyze(ElementController.java:980) at ast.BesserWissA.dispatch(BesserWissA.java:408) < Explanation of code: In this testcode Ive written some hardcode to read exactly two tables out of a writer document. I get the tables via a table supplier and get there ranges by using getAnchor() of each XTable. I put the anchors for compairing to a XTextRangeCompare object using compareRegionStarts() and that throws an IllegalArgumentException. Ive checked out the XTextRange object by getAnchor(). Most members are set to null, just object members are not. But the members of that objects are null again. So the XTextRange I ve got is invalid in my eyes. Code: XComponentContext m_aComponentContext; // given XMultiComponentFactory m_aMCF = m_aComponentContext.getServiceManager(); Object desktop = null; try { desktop = m_aMCF.createInstanceWithContext("com.sun.star.frame.Desktop", m_aComponentContext); } catch(Exception ex) { } XDesktop xDesktop = (XDesktop) UnoRuntime.queryInterface( XDesktop.class, desktop); XComponent xComponent = xDesktop.getCurrentComponent(); XTextTablesSupplier xTextTablesSupplier = (XTextTablesSupplier) UnoRuntime. queryInterface(XTextTablesSupplier.class, xComponent); XNameAccess xNamedTables = xTextTablesSupplier.getTextTables(); String[] tableNames = xNamedTables.getElementNames(); XTextRange[] myRanges = new XTextRange[2]; System.out.println( "compairing ranges of " + tableNames[0] + " & " + tableNames[1]); // just read out first two tables for(int k = 0; k < 2 k++) { XTextTable table = null; XTextContent xTC = null; try { Object obj = xNamedTables.getByName(tableNames[k]); table = (XTextTable) UnoRuntime.queryInterface(XTextTable.class, obj); } catch(Exception ex) { } //myRanges[k] = table.getAnchor().getStart(); // same problem here, same exc myRanges[k] = table.getAnchor(); } XTextRangeCompare xTextRangeCompare = (XTextRangeCompare) UnoRuntime. queryInterface(XTextRangeCompare.class, m_textDoc.getText()); int k = -1000; try { k = xTextRangeCompare.compareRegionStarts(myRanges[0], myRanges[1]); } catch(IllegalArgumentException ex) { } System.out.println(k);
target set
Reset assigne to the default "issues@openoffice.apache.org".