UNO - CreateUnoService("...") = <null>

Hi Folks,

UNO is not working, meaning CreateUnoService("…") returns <.null.>. I understand that this is all Java foolishness and I have confirmed that java seems to be in working order. I can invoke the UNO environment from a simple java program, but this doesn’t explain why the calls to CreateUnoService fail in the context of LibreOffice macros:

import com.sun.star.uno.XComponentContext;
import com.sun.star.comp.helper.Bootstrap;

public class TestUNO {
    public static void main(String[] args) {
        try {
            // Bootstrap the UNO runtime
            XComponentContext xContext = Bootstrap.bootstrap();
            if (xContext != null) {
                System.out.println("UNO is available.");
            } else {
                System.out.println("UNO is NOT available.");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Sure could use some advice here …

Thanks for the help,

Chris.

Do you mean the Basic CreateUnoService function?

Yes, this function returns null if the service name is incorrectly specified. Note that the service name is case-sensitive.

It turns out that this was my problem. Ironically, I did not include the one piece that would have solved it – the name of the service I was trying to create

Thanks for the help,

Chris.

1 Like

a macro is called in an existing context, you receive it as parameter, so don’t have to “bootstrap” yourself.

ex. LibreOffice Developer's Guide: Chapter 18 - Scripting Framework - The Document Foundation Wiki

public class HelloWorld {
    public static void printHW(XScriptContext xScriptContext)
    {
        XModel xDocModel = xScriptContext.getDocument();
 ...