Reputation: 11
I am a complete beginner so please have patience. I am trying to run this script:
import java.util.Scanner;
public class Echo {
public static void main(String[] args) {
String line;
Scanner in = new Scanner(System.in);
System.out.print("Type something: ");
line = in.nextLine();
System.out.println("You said: " + line);
}
}
in my Jupyter kernel with SciJava, but I get this error:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script6.groovy: 7: expecting '}', found 'in' @ line 7, column 17.
Scanner in = new Scanner(System.in);
^
1 error
at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
at org.codehaus.groovy.control.ErrorCollector.addFatalError(ErrorCollector.java:150)
at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:120)
at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:132)
at org.codehaus.groovy.control.SourceUnit.addError(SourceUnit.java:350)
at org.codehaus.groovy.antlr.AntlrParserPlugin.transformCSTIntoAST(AntlrParserPlugin.java:144)
at org.codehaus.groovy.antlr.AntlrParserPlugin.parseCST(AntlrParserPlugin.java:110)
at org.codehaus.groovy.control.SourceUnit.parse(SourceUnit.java:234)
at org.codehaus.groovy.control.CompilationUnit$1.call(CompilationUnit.java:168)
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:943)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:605)
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:581)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:558)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:254)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:250)
at org.scijava.plugins.scripting.groovy.GroovyScriptEngine.getScriptClass(GroovyScriptEngine.java:319)
at org.scijava.plugins.scripting.groovy.GroovyScriptEngine.eval(GroovyScriptEngine.java:122)
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
at org.scijava.script.ScriptModule.run(ScriptModule.java:160)
at org.scijava.module.ModuleRunner.run(ModuleRunner.java:168)
at org.scijava.jupyter.kernel.evaluator.Worker.run(Worker.java:108)
at org.scijava.thread.DefaultThreadService$2.run(DefaultThreadService.java:221)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
I tried to run the program through a script in my command terminal and it worked. To add, I have run other simple scripts before in this kernel but for some reason this one does not work.
If need be, please refer to the screenshot attached.
I am on macOS Mojave.
Thank you in advance!
Upvotes: 1
Views: 241
Reputation: 3506
SciJava is a polyglot kernel which means it supports many different languages.
The README and notebook linking to the supported languages suggests that java is supported but the default is Groovy:
Some of the supported languages are Groovy (default), Python, Beanshell, Clojure, Java, Javascript, Ruby and Scala.
Although https://github.com/scijava/scijava-jupyter-kernel/issues/80 suggests java it is not operational.
Groovy is not java. It is fairly compatible but there are differences one of which you have found. in
is a keyword in groovy and cannot be used as a variable name (see section 13).
The below is the same program in valid groovy:
import java.util.Scanner;
public class Echo {
public static void main(String[] args) {
String line;
Scanner input = new Scanner(System.in);
System.out.print("Type something: ");
line = input.nextLine();
System.out.println("You said: " + line);
}
}
Although this leads to the next issue that stdin is not supported https://github.com/scijava/scijava-jupyter-kernel/issues/96 but hopefully the answer so far untangles the error message you are originally getting.
Upvotes: 1