Editor does not contain a main type

后端 未结 30 2152
执笔经年
执笔经年 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:28

    I have this problem a lot with Eclipse and Scala. It helps if you clean your workspace and rebuild your Project.

    Sometimes Eclipse doesn't recognize correctly which files it has to recompile :(

    Edit: The Code runs fine in Eclipse

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

    One more thing to check: make sure that your source file contains the correct package declaration corresponding to the subdirectory it's in. The error mentioned by the OP can be seen when trying to run a "main type" declared in a file in a subdirectory but missing the package statement.

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

    I had the same problem. I tried all sorts of things. And I came to know that

    1. My .java files were not linked and
    2. they were not placed in the 'src' folder.

    Things I did:

    Project properties >> Java Build Path >> Source

    • Deleted the original 'src' folder which was empty using 'Remove' option
    • Added the source that contained my source .java files using the 'Add Folder' option

    This solved the error.

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

    A simpler way is to close the project and reopen it.

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

    Follow the below steps:

    1. Backup all your .java files to some other location
    2. delete entire java project
    3. Create new java project by right click on root & click new
    4. restore all the files to new location !!
    0 讨论(0)
  • 2020-11-27 14:33
    ***
    

    Just close and reopen

    *** your project in eclipse. Sometime there are linkage problems. This solved my problem

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