Reputation: 616
I have just started learning scala, i am using the eclipse ide for it, in the run configuration i have set scala application with the project name and as main class main when i compile i have
Error: Could not find or load main class main
when i check the console i see it's reading from Java/jre directory, is it normal or should i change that ? This is the code
package one
class Main {
object Bottles {
def main(args: Array[String]){
var n : Int=2;
while(n<=6){
println(s"Hello ${n} bottles");
n+=1;
}
}
}
}
Upvotes: 2
Views: 4899
Reputation: 1954
Okay, also had the same error Error: "Could not find or load main class main" in my Scala IDE and the reason of that was that when I created Main, I immediately moved it to a package.
So I had to:
Upvotes: 2
Reputation: 21700
The main
method needs to be on a toplevel object. Your Bottles
object is wrapped in a Main
class. Remove that Main
class and your code should run.
object Bottles {
def main(args: Array[String]){
var n : Int=2;
while(n<=6){
println(s"Hello ${n} bottles");
n+=1;
}
}
}
Upvotes: 1