Just going through the sample Scala code on Scala website, but encountered an annoying error when trying to run it.
Here\'s the code: http://www.scala-lang.org/node/
Make sure that your .java file is present either in the str package, or in some other package. If the java file with the main function is outside all packages, this error is thrown.
I had the same problem. I had the main class out of the src package, in other folder. I move it in and correct folder and solved
Try 'Update Project'. Once I did this, The Run as Java Application option appeared.
In my particular 'Hello World' case the cause for this problem was the fact, that my main()
method was inside the Scala class
.
I put the main()
method under the Scala object
and the error disappeared.
That is because Scala object
in Java terms is the entity with only static members and methods inside.
That is why Java's public static void main()
in Scala must be placed under object
.
(Scala class
may not contain static's inside)
The correct answer is: the Scala library needs to before the JRE library in the buildpath.
Go to Java Buildpath > Order and Export and move Scala library to the top
I had this problem with a Java project that I imported from the file system (under Eclipse Helios). Here's a hint: the src code didn't seem to be compiled at all, as no "bin" directory showed up.
I had to create a Java project from scratch (using the wizard), then compare the .project
files of the non-working and working projects.
The project giving "Editor does not contain a main type" had this as the "buildSpec" in the .project file:
<buildSpec>
</buildSpec>
But the working project had this as the "buildSpec":
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
I copied this in, and the imported project worked.
I know my answer is for Java, but the same might be the issue for your Scala project.