command line arguments - Scala Args Parsing -
why does
println("hello, " + args(0) + "!")
work when run scala nomain.scala but
object helloworld { def main(args: list[string]) { println("hello, " + args(0) + "!") } }
gives me error:
java.lang.nosuchmethodexception: main.main([ljava.lang.string;) @ java.lang.class.getmethod(class.java:1786) @ scala.reflect.internal.util.scalaclassloader.run(scalaclassloader.scala:94) @ scala.reflect.internal.util.scalaclassloader.run$(scalaclassloader.scala:90) @ scala.reflect.internal.util.scalaclassloader$urlclassloader.run(scalaclassloader.scala:129) @ scala.tools.nsc.commonrunner.run(objectrunner.scala:22) @ scala.tools.nsc.commonrunner.run$(objectrunner.scala:21) @ scala.tools.nsc.objectrunner$.run(objectrunner.scala:39) @ scala.tools.nsc.commonrunner.runandcatch(objectrunner.scala:29) @ scala.tools.nsc.commonrunner.runandcatch$(objectrunner.scala:28) @ scala.tools.nsc.objectrunner$.runandcatch(objectrunner.scala:39) @ scala.tools.nsc.scriptrunner.runcompiled(scriptrunner.scala:170) @ scala.tools.nsc.scriptrunner.$anonfun$runscript$1(scriptrunner.scala:187) @ scala.tools.nsc.scriptrunner.$anonfun$runscript$1$adapted(scriptrunner.scala:187) @ scala.tools.nsc.scriptrunner.$anonfun$withcompiledscript$2(scriptrunner.scala:156) @ scala.tools.nsc.scriptrunner.runscript(scriptrunner.scala:124) @ scala.tools.nsc.scriptrunner.runscriptandcatch(scriptrunner.scala:200) @ scala.tools.nsc.maingenericrunner.runtarget$1(maingenericrunner.scala:63) @ scala.tools.nsc.maingenericrunner.run$1(maingenericrunner.scala:88) @ scala.tools.nsc.maingenericrunner.process(maingenericrunner.scala:99) @ scala.tools.nsc.maingenericrunner$.main(maingenericrunner.scala:104) @ scala.tools.nsc.maingenericrunner.main(maingenericrunner.scala)
when run scala helloworld.scala
i tried adding statements if (args.size > 0)
gives me errors. wondering doing wrong here. wondering how check see if list has in , how directly print args.
def main(args: array[string]): unit = ???
should instead of
def main(args: list[string]): unit = ???
Comments
Post a Comment