2

I'm new to scala and I would like to run some of the codes that I'm doing for a course I'm taking in coursera about this language but the problem is that I can't run my code in InteliJJ 2016, I already installed the plugin but the option for running doesn't come along and when I click it in the toolbar it takes me to Edit Configuration and if I select Scala Console it would not run, I need to declare the methods again since the ones in my file won't compile. Any idea? I'll post pictures.

Here is my Project SDK (JDK) and Scala SDK which are updated to date: enter image description here

Here I created a new Scala object in src folder and created a method and clicked in the toolbar the run option and this menu appears... if I click scala console it won't run my project, I need to write my code again in the console for it to work: enter image description here What to do now?

barfuin
  • 16,865
  • 10
  • 85
  • 132
andrade94
  • 21
  • 3

4 Answers4

3

I have tried the method of adding def main(){...}, which did not seem to work.

On the other hand, extending App as follows does provide the "Run" option on the contextual menu for the Scala object:

object ScalaTest extends App {
     print ("test")
}

For some reason IntelliJ 2016.1 does not recognize def main(){} as a valid runnable file and prevents the menu from showing the run option.

I found the answer on a similar question on SO: Cannot run Scala file in Intellij

I hope this helps.

Run option appears in menu Running the scala object

Community
  • 1
  • 1
autronix
  • 2,885
  • 2
  • 22
  • 28
1

I had the similar issue and I simply re-installed the scala plugin and it started to recognize my 'main' methods.

Shendor
  • 749
  • 2
  • 11
  • 18
0

You need to write main method in a scala object. For example:

object ScalaTest {
 def main () {
     print ("test")
 }
}

Then you must right-click on ScalaTest file and you will see "Run" command. That's it.

jon hanson
  • 8,722
  • 2
  • 37
  • 61
aykut
  • 1
  • 2
0

Had the same problem and it was solved by reverting my jdk from 9 to 8. I know this is not the OP's problem but this might be of some use to somebody.

yannick1976
  • 10,171
  • 2
  • 19
  • 27