将 java 包导入到 scala 项目时出现问题 (IntelliJ 10.5.2)

发布于 2024-12-08 20:22:51 字数 266 浏览 1 评论 0原文

尝试将“import”语句添加到我的新 scala 项目(我现在使用 IntelliJ 10.5.2)语法荧光笔告诉我他找不到 java 包:

import java.util.zip //Cannot resolve symbol java

object Main extends App {

    override def main(args: Array[String]) {

    }
}

出了什么问题。我应该怎么做才能导入这个包?

Trying to add "import" statement to my new scala project (I'm using IntelliJ 10.5.2 right now) syntax highlighter tells me that he cannot find java package:

import java.util.zip //Cannot resolve symbol java

object Main extends App {

    override def main(args: Array[String]) {

    }
}

What's wrong. What should I do to import this package?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

赠意 2024-12-15 20:22:51

确保您已在以下位置配置了 Java SDK:

File ->项目结构->项目->项目 SDK

请参阅在哪里配置项目 JDK

Make sure that you have a Java SDK configured under:

File -> Project Structure -> Project -> Project SDK

See Where do I configure project JDK

终弃我 2024-12-15 20:22:51

文件->项目结构->平台设置-> SDK->将 JDK 主路径更改为最新 JDK 版本的正确位置。

就我而言,路径设置为 /usr/lib/jvm/java-1.11.0-openjdk-amd64,因此我将其更改为 /usr/lib/jvm/java- 11-openjdk-amd64 和我所有的导入突然从红色变成白色,并且我的 scala 项目中不再有由于未知的 java 类/方法而出现的错误警告。

OBS:IntelliJ 显示的错误纯粹是图形化的,因为我可以构建我的项目。但是当我构建它们时,我的红色导入将被 ide 删除。修复后问题就消失了。

我的 IntelliJ 配置:

IntelliJ IDEA 2019.3.2 (Community Edition)
Build #IC-193.6015.39, built on January 21, 2020
Runtime version: 11.0.5+10-b520.30 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 4.15.0-74-generic
GC: ParNew, ConcurrentMarkSweep
Memory: 1998M
Cores: 6
Registry: 
Non-Bundled Plugins: org.intellij.scala

File -> Project Structure -> Platform Settings -> SDKs -> change your JDK home path to the correct location of your latest JDK version.

In my case, the path was set as /usr/lib/jvm/java-1.11.0-openjdk-amd64, so I changed it to /usr/lib/jvm/java-11-openjdk-amd64 and all my imports suddenly went from red to white, and there were no more error warnings in my scala project due to unknown java classes/methods.

OBS: The errors shown by IntelliJ were purely graphical, since I could build my project. But when I built them, my red imports would be removed by the ide. After this fix the problems desapeared.

My IntelliJ configuration:

IntelliJ IDEA 2019.3.2 (Community Edition)
Build #IC-193.6015.39, built on January 21, 2020
Runtime version: 11.0.5+10-b520.30 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 4.15.0-74-generic
GC: ParNew, ConcurrentMarkSweep
Memory: 1998M
Cores: 6
Registry: 
Non-Bundled Plugins: org.intellij.scala
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文