2

我用中文评论 Rational.scala 文件的代码行,如下所示:

var a = new Rational(-4,6)
var b = new Rational(3,-9)
var c = a + a * b //满足运算符的优先级别 

当我运行命令时:

scala Rational.scala

它抛出一个异常。而我留下评论或用英文评论,没关系!

我要配置什么?

很感谢

仅供参考:这是例外:

java.lang.ClassNotFoundException: Main (args = , classpath = d:\DOCUME~1\LUJUNM~1\LOCALS~1\Temp\scalascript3969467400078546162.tmp;C:\Program%20Files\
Java\jdk1.6.0_20\jre\lib\resources.jar;C:\Program%20Files\Java\jdk1.6.0_20\jre\lib\rt.jar;C:\Program%20Files\Java\jdk1.6.0_20\jre\lib\jsse.jar;C:\Prog
ram%20Files\Java\jdk1.6.0_20\jre\lib\jce.jar;C:\Program%20Files\Java\jdk1.6.0_20\jre\lib\charsets.jar;C:\Program%20Files\Java\jdk1.6.0_20\jre\lib\ext\
dnsns.jar;C:\Program%20Files\Java\jdk1.6.0_20\jre\lib\ext\localedata.jar;C:\Program%20Files\Java\jdk1.6.0_20\jre\lib\ext\sunjce_provider.jar;C:\Progra
m%20Files\Java\jdk1.6.0_20\jre\lib\ext\sunmscapi.jar;C:\Program%20Files\Java\jdk1.6.0_20\jre\lib\ext\sunpkcs11.jar;C:\SCALA-~1.FIN\bin\..\lib\jline.ja
r;C:\SCALA-~1.FIN\bin\..\lib\scala-compiler.jar;C:\SCALA-~1.FIN\bin\..\lib\scala-dbc.jar;C:\SCALA-~1.FIN\bin\..\lib\scala-library.jar;C:\SCALA-~1.FIN\
bin\..\lib\scala-swing.jar;C:\SCALA-~1.FIN\bin\..\lib\scalap.jar;C:\Program%20Files\Java\jdk1.6.0_20\bin;C:\Program%20Files\Java\jdk1.6.0_20\lib)
        at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.run(ScalaClassLoader.scala:103)
        at scala.tools.nsc.ObjectRunner$.run(ObjectRunner.scala:33)
        at scala.tools.nsc.ObjectRunner$.runAndCatch(ObjectRunner.scala:40)
        at scala.tools.nsc.ScriptRunner.scala$tools$nsc$ScriptRunner$$runCompiled(ScriptRunner.scala:171)
        at scala.tools.nsc.ScriptRunner$$anonfun$runScript$1.apply(ScriptRunner.scala:188)
        at scala.tools.nsc.ScriptRunner$$anonfun$runScript$1.apply(ScriptRunner.scala:188)
        at scala.tools.nsc.ScriptRunner$$anonfun$withCompiledScript$1.apply$mcZ$sp(ScriptRunner.scala:157)
        at scala.tools.nsc.ScriptRunner$$anonfun$withCompiledScript$1.apply(ScriptRunner.scala:131)
        at scala.tools.nsc.ScriptRunner$$anonfun$withCompiledScript$1.apply(ScriptRunner.scala:131)
        at scala.tools.nsc.util.package$.waitingForThreads(package.scala:26)
        at scala.tools.nsc.ScriptRunner.withCompiledScript(ScriptRunner.scala:130)
        at scala.tools.nsc.ScriptRunner.runScript(ScriptRunner.scala:188)
        at scala.tools.nsc.ScriptRunner.runScriptAndCatch(ScriptRunner.scala:201)
        at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:58)
        at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:80)
        at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:89)
        at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
4

1 回答 1

2

您的问题是您使用的是 Windows,而 Windows 的默认字符集不是 UTF-8。

做这个:

  1. 确保您知道写入源文件的字符集是什么。最好是 UTF-8。

  2. 使用参数-encoding指定要使用的字符集。例如,scalac -enconding utf8 Rational.scala

于 2012-05-08T00:13:18.673 回答