无法在 IntelliJ 上创建 Scala 类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38006735/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unable to create Scala class on IntelliJ
提问by Saurav Sircar
I'm just starting to learn Scala. I have installed the Scala plugin for IntelliJ, and created a new Scala project. But when I right-click on the src folder to make a new Scala class, there is no option to do so. Am I missing something?
我刚刚开始学习 Scala。我已经为 IntelliJ 安装了 Scala 插件,并创建了一个新的 Scala 项目。但是当我右键单击 src 文件夹以创建一个新的 Scala 类时,没有选择这样做。我错过了什么吗?
回答by Majico
Right click on your project, "Add Framework support" and choose Scala framework, then by right click on the packages you can create Scala Class.
右键单击您的项目,“添加框架支持”并选择 Scala 框架,然后通过右键单击您可以创建 Scala 类的包。
After this, right click on src> Mark directory as> Sources Root.
在此之后,右键单击src> Mark directory as> Sources Root。
Doing both of these should fix your problem!
做这两个应该可以解决你的问题!
回答by user1761806
I figured it out, right click on src > Mark directory as > Sources Root.
我想通了,右键单击 src > 将目录标记为 > Sources Root。
Now try again.
现在再试一次。
回答by Mike Pors
I just had this issue, also. It turned out that IntelliJ hadn't marked my src/main/scalafolder as a "source" folder.
我也刚遇到这个问题。事实证明,IntelliJ 没有将我的src/main/scala文件夹标记为“源”文件夹。
To do this: Project Structure -> Modules ->right click folder and Mark as "Source"(blue)
为此:Project Structure -> Modules ->右键单击文件夹和Mark as "Source"(蓝色)
Similarly the src/main/testfolder wasn't marked as a test folder. I was able to add scala classes after those folders were appropriately marked.
同样,该src/main/test文件夹未标记为测试文件夹。在这些文件夹被适当标记后,我能够添加 Scala 类。
回答by cwadeevans
I had this problem everytime I created a new project with spaces in the name. eg "Hell Wev". Using "HellWev" or similar as a project name seems to work fine
每次我创建一个名称中有空格的新项目时,我都会遇到这个问题。例如“Hell Wev”。使用“HellWev”或类似名称作为项目名称似乎工作正常
回答by Eric Aldinger
In IDEA 2016.2.5
在 IDEA 2016.2.5
From a new SBT or Scala project.
来自新的 SBT 或 Scala 项目。
- Open Project Structure
- On the Project tab add your JDK (should also be visible in SDKs tab)
- Under Global Libraries add Scala SDK.
- 开放项目结构
- 在 Project 选项卡上添加您的 JDK(也应该在 SDKs 选项卡中可见)
- 在全局库下添加 Scala SDK。
Sadly just adding this to your build.SBT does not impact the IDE behavior.
遗憾的是,将它添加到 build.SBT 不会影响 IDE 行为。
回答by Claudio
回答by svk 041994
Go to Src folder and choose Mark as Directory then choose the option called source root, that would fix your problem.
转到 Src 文件夹并选择标记为目录,然后选择名为 source root 的选项,这将解决您的问题。
回答by Christina Sebastian
I had the same problem and what I did is Right Clicked on the Project ---> Then Choose Add Framework Support--> In the Left hand corner there was a list mentioned of Groovy, Kotlin, Maven and Scala.---> From the List I choose Scala but still had issue because the librabry was not specified--->Clicked on Create and it asked me to choose the version as I had Installed 2.11.12, i choose it and it started downloading it. Once it was downloaded I selected Scala and the issue was fixed.
我遇到了同样的问题,我所做的是右键单击项目 ---> 然后选择添加框架支持--> 在左手角有一个提到 Groovy、Kotlin、Maven 和 Scala 的列表。--->从列表中,我选择了 Scala,但仍然有问题,因为未指定库--->单击“创建”,它要求我选择安装 2.11.12 的版本,我选择它并开始下载它。下载后,我选择了 Scala,问题就解决了。
回答by techie95
add
libraryDependencies += "org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.50"in target -> built.sbtfile
this works for IntelliJ IDEA 2017
添加
libraryDependencies += "org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.50"目标 ->built.sbt文件,这适用于 IntelliJ IDEA 2017


