将 java 包导入到 scala 项目时出现问题 (IntelliJ 10.5.2)
尝试将“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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确保您已在以下位置配置了 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
文件->项目结构->平台设置-> 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 配置:
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: