IntelliJ Scala 配置问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25597995/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 06:31:43  来源:igfitidea点击:

IntelliJ Scala configuration issue

scalapluginsintellij-idea

提问by Sven Vidak

So, I downloaded Scala and configured paths, I can run Scala console from terminal, Scala plugin is installed and "hello world" is running...

所以,我下载了 Scala 并配置了路径,我可以从终端运行 Scala 控制台,安装了 Scala 插件并且“hello world”正在运行......

The problem is that, when I write a "hello world" program:

问题是,当我编写“hello world”程序时:

object First {
   def main(args: Array[String]): Unit = {
      println(12)
   }
}

it says: Cannot resolve symbol println

它说: Cannot resolve symbol println

As I said, I can run this program and it prints out 12... Also, if I create a List or an array it "cannot resolve symbol" but everything runs with no problem at all...

正如我所说,我可以运行这个程序并打印出 12 ... 此外,如果我创建一个 List 或一个数组,它“无法解析符号”但一切运行都没有问题......

In most cases I've found, there was problem with Java set up, but that's not the case here...

在我发现的大多数情况下,Java 设置存在问题,但这里的情况并非如此......

回答by larsonmattr

Within File->Project Structure, make sure that there is a scala library in Project Settings\LibrariesOr, make sure that you have added scala-compiler.jar, scala-library.jar to your project.

File-> 中Project Structure,确保Project Settings\中有一个 scala 库,Libraries或者,确保您已将 scala-compiler.jar、scala-library.jar 添加到您的项目中。

If it is still acting strange, try File->Invalidate Cache/Restart

如果它仍然表现得很奇怪,请尝试File->Invalidate Cache/Restart

I had a similar issue with IntelliJ for an SBT project I started, with a correctly installed Scala 2.11 library, etc. Invalidate Cache fixed it so that IntelliJ could find the symbols.

对于我开始的 SBT 项目,我在 IntelliJ 上遇到了类似的问题,正确安装了 Scala 2.11 库等。无效缓存修复了它,以便 IntelliJ 可以找到符号。

回答by qiubix

Ensure, that you have scala-library.jar and scala-compiler in your project libraries.

确保您的项目库中有 scala-library.jar 和 scala-compiler。

Then try invalidating cache (File->Invalidate Caches/Restart->Invalidate and Restart).

然后尝试使缓存无效(文件-> 使缓存无效/重新启动-> 无效并重新启动)。

If it's still not working, try reloading all your maven projects. You can either reimport them manually or go to Maven Projects->Reimport All Maven Projects (blue arrows).

如果它仍然不起作用,请尝试重新加载所有 Maven 项目。您可以手动重新导入它们,也可以转到 Maven Projects->Reimport All Maven Projects(蓝色箭头)。

I had similar issue and the last thing worked for me.

我有类似的问题,最后一件事对我有用。

I hope it helps :)

我希望它有帮助:)

回答by Ting Jia

I have the same issue when I use the idea 15, and fixed it in these 2 steps:

当我使用想法 15 时,我遇到了同样的问题,并在以下两个步骤中修复了它:

  1. File -> Project Structure -> Libraries -> + -> Scala SDK -> your version -> OK

  2. Maven Projects -> choose your scala project -> Lifecycle -> clean -> compile

  1. 文件 -> 项目结构 -> 库 -> + -> Scala SDK -> 你的版本 -> OK

  2. Maven 项目 -> 选择你的 Scala 项目 -> 生命周期 -> 清理 -> 编译

Done

完毕

回答by hossein

if your version IntelliJ IDEA 2016.3.4

如果你的版本是 IntelliJ IDEA 2016.3.4

Worksheet configuration error:: Can't find Scala module to run

工作表配置错误:: 找不到要运行的 Scala 模块

project structure > Modules > + > new modules > scala > scala

项目结构 > 模块 > + > 新模块 > scala > scala

回答by Ken Williams

I had this problem - it turned out to be caused by me upgrading Java on my Mac, so that my JDK's path (/Library/Java/JavaVirtualMachines/jdk1.8.0_172.jdk/Contents/Home) was no longer valid. I went into my Project Structure settings and updated the path to /Library/Java/Home, then the project could see the proper Java libraries.

我遇到了这个问题 - 结果证明是我在 Mac 上升级 Java 造成的,因此我的 JDK 路径 ( /Library/Java/JavaVirtualMachines/jdk1.8.0_172.jdk/Contents/Home) 不再有效。我进入了我的项目结构设置并将路径更新为/Library/Java/Home,然后项目可以看到正确的 Java 库。

enter image description here

在此处输入图片说明

回答by ekeyser

Don't know if this will help, but it worked with my environment. Navigate to:

不知道这是否会有所帮助,但它适用于我的环境。导航:

File> Project Structure> Modules

File> Project Structure>Modules

Then, when I tried to apply a minor change, I got a message about how the Content Roots was being shared between two different Modules (a conflict). After removing the conflicting Content Root(s) from one of the Modules, IntelliJ started resolving symbols correctly.

然后,当我尝试应用一个小的更改时,我收到一条关于内容根如何在两个不同模块之间共享的消息(冲突)。从模块之一中删除冲突的内容根后,IntelliJ 开始正确解析符号。

You will see Content Roots on the right-hand side of the dialog box under module "Sources" tab.

您将在模块“源”选项卡下的对话框右侧看到内容根。

I have no idea if the conflict in "Content Root" was what kept IntelliJ from resolving symbols, but fixing this error cleared everything up without having to change anything else.

我不知道“内容根”中的冲突是否是导致 IntelliJ 无法解析符号的原因,但是修复此错误可以清除所有内容而无需更改任何其他内容。