user3116355
user3116355

Reputation: 1197

Error running scala console. Module not found

I am able to run sample code, which I have saved in sample.sc and the results are displaying on Scala console. But I get an error when running the following program, which I saved as the Timeprogram.scala script:

/**
 * Created by sarathrnair on 3/18/15.
 */


println ( "Enter the seconds" )

val totalSeconds=readInt()
val displaySeconds=totalSeconds%60
val totalMinutes=totalSeconds/60
val displayMinutes=totalMinutes%60
val displayHours=totalMinutes/60
val sec=displaySeconds.toString
val min=displayMinutes.toString
val finalString=displayHours+":"+("0"*(2-min.length))+min+":"+("0"*(2-sec.length))+sec

println (finalString)

The error I get is:

Error running scala console. Module is not specified.

Please help me determine the reason behind this error.

Upvotes: 6

Views: 17668

Answers (3)

Stephen
Stephen

Reputation: 401

The reason for the error mentioned when selecting "Run Scala Console", i.e. -

Error running scala console. Module is not specified.

is that there is no module specified in the Scala Console Run Configuration. Click on the run configuration dropdown and select "Edit Configurations..." There you can specify a module.

enter image description here

But this is just if you want to open a REPL shell within IntelliJ. If you just want to run the Scala program do it as in the accepted answer and just select "Run" instead of "Run Scala Console".

Upvotes: 21

Cass Q
Cass Q

Reputation: 21

Because you haven't set up the module yet. Open the configurations of the project and set this project as the module.

Upvotes: 2

Ajay Padala
Ajay Padala

Reputation: 2401

If its a .scala file you need to wrap it into an object that extends App like:

object Timeprogram extends App {
  // Your program here
}

Upvotes: 4

Related Questions