Scala in IntelliJ error

1.1k views Asked by At

I just downloaded the plug in for Scala in IntelliJ and have created a project but now have various errors I read that the problem can be that I am missing a library. But when I try and go to project structure -> dependencies to add a library I have no clue where in the files to look for a library. enter image description here The errors are really simple but I can't seem to figure it out.

Any suggestions would be helpful :)

3

There are 3 answers

0
Madoc On

Scala source files end in .scala, not .java. Try renaming Counter.java to Counter.scala. This should improve things a lot.

0
AmigoNico On

You can save yourself a lot of trouble by creating a simple SBT project that specifies all of your dependencies, etc. and then just pointing the IDE at that. Then when you change build.sbt, IntelliJ IDEA will notice that and update itself automatically. Plus, your build.sbt gets checked into your code base so that anyone you are collaborating with sees your changes to the dependencies. And the project can be built in batch mode using sbt compile and friends.

The following page talks about IntelliJ IDEA's "SBT Import" feature:

https://confluence.jetbrains.com/display/IntelliJIDEA/Getting+Started+with+SBT

1
Mateusz Dymczyk On

Here's everything you need to properly set up Scala plugin in Intellij. Furthermore your code has several errors:

Are you sure you created a Scala project (when you did File->New->Project)? This looks to me like a Java project? That class file looks to me like a Java class not a Scala class (that's why you're getting compilation errors on def but not public class).

1) value is not defined anywhere, of course it will throw a compilation error

2) classes in Scala are by default public, you do not (cannot) mark them as such