[英]Scala in IntelliJ error
I just downloaded the plug in for Scala in IntelliJ and have created a project but now have various errors I read that the problem can be that I am missing a library. 我刚刚在IntelliJ中下载了Scala的插件,并创建了一个项目,但现在有各种错误,我读到问题可能是我错过了一个库。 But when I try and go to project structure -> dependencies to add a library I have no clue where in the files to look for a library.
但是当我尝试去项目结构 - >依赖项添加库时,我不知道在文件中查找库的位置。
The errors are really simple but I can't seem to figure it out.
错误很简单,但我似乎无法弄明白。
Any suggestions would be helpful :) 任何的意见都将会有帮助 :)
Here's everything you need to properly set up Scala plugin in Intellij. 以下是在Intellij中正确设置Scala插件所需的一切。 Furthermore your code has several errors:
此外,您的代码有几个错误:
Are you sure you created a Scala project (when you did File->New->Project)? 您确定创建了Scala项目(当您执行File-> New-> Project时)? This looks to me like a Java project?
这对我来说就像一个Java项目? That class file looks to me like a Java class not a Scala class (that's why you're getting compilation errors on
def
but not public class
). 那个类文件看起来像一个Java类而不是Scala类(这就是为什么你在
def
而不是public class
上得到编译错误的原因)。
1) value
is not defined anywhere, of course it will throw a compilation error 1)
value
没有在任何地方定义,当然它会抛出一个编译错误
2) classes in Scala are by default public
, you do not (cannot) mark them as such 2)Scala中的类默认为
public
,您不能(不能)将它们标记为public
You can save yourself a lot of trouble by creating a simple SBT project that specifies all of your dependencies, etc. and then just pointing the IDE at that. 通过创建一个指定所有依赖项等的简单SBT项目,然后只需将IDE指向该项目,您就可以省去很多麻烦。 Then when you change
build.sbt
, IntelliJ IDEA will notice that and update itself automatically. 然后,当您更改
build.sbt
,IntelliJ IDEA会注意到并自动更新。 Plus, your build.sbt
gets checked into your code base so that anyone you are collaborating with sees your changes to the dependencies. 另外,您的
build.sbt
会被检入您的代码库,以便与您协作的任何人都可以看到您对依赖项的更改。 And the project can be built in batch mode using sbt compile
and friends. 并且可以使用
sbt compile
和friends在批处理模式下构建项目。
The following page talks about IntelliJ IDEA's "SBT Import" feature: 以下页面讨论了IntelliJ IDEA的“SBT导入”功能:
https://confluence.jetbrains.com/display/IntelliJIDEA/Getting+Started+with+SBT https://confluence.jetbrains.com/display/IntelliJIDEA/Getting+Started+with+SBT
Scala source files end in .scala
, not .java
. Scala源文件以
.scala
结尾,而不是.java
。 Try renaming Counter.java
to Counter.scala
. 尝试将
Counter.java
重命名为Counter.scala
。 This should improve things a lot. 这应该会改善很多事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.