franza
franza

Reputation: 2317

Troubles with importing java package to scala project (IntelliJ 10.5.2)

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?

Upvotes: 6

Views: 4401

Answers (2)

João Luca
João Luca

Reputation: 29

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

Upvotes: 0

retronym
retronym

Reputation: 55028

Make sure that you have a Java SDK configured under:

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

See Where do I configure project JDK

Upvotes: 15

Related Questions