0

I'm creating a java program which controls iTunes. I created most of the code on my Mac mini. Everything works fine on the mini. But when I try to run the program on my MacBook, I get an error. The NullPointerException occurs when I try to run an AppleScript. But just on the MacBook.

Here is the code:

        String scriptRestart = "tell application \"iTunes\" \nset player position to 0 \nend tell";
    ScriptEngineManager mgr = new ScriptEngineManager();
    ScriptEngine engine = mgr.getEngineByName("AppleScriptEngine");
        try {
            engine.eval(scriptRestart); // NullPointerException
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

Had someone a problem like this before? Is this error related to the java version?

Thanks.

EDIT I do know what an NullPointerException is. This is a strange problem, because it works on my mac mini, but not on my MacBook. So the code should be fine.

Mike_NotGuilty
  • 2,253
  • 5
  • 32
  • 64

1 Answers1

1

I found the problem!

It only works if you install "Java for OS X 2015-001".

After downloading here LINK , it works!

Mike_NotGuilty
  • 2,253
  • 5
  • 32
  • 64