Editor does not contain a main type

后端 未结 30 2156
执笔经年
执笔经年 2020-11-27 13:51

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/

相关标签:
30条回答
  • 2020-11-27 14:41

    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.

    0 讨论(0)
  • 2020-11-27 14:41

    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

    0 讨论(0)
  • 2020-11-27 14:42

    Try 'Update Project'. Once I did this, The Run as Java Application option appeared.

    0 讨论(0)
  • 2020-11-27 14:42

    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)

    0 讨论(0)
  • 2020-11-27 14:44

    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

    0 讨论(0)
  • 2020-11-27 14:44

    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.

    0 讨论(0)
提交回复
热议问题