Eclipse can't find / load main class

前端 未结 20 2091
猫巷女王i
猫巷女王i 2020-12-05 04:40

My Eclipse (Indigo) was running just fine. I created a simple class Hello. It is placed in package cont in the folder ch13. However

相关标签:
20条回答
  • 2020-12-05 04:58

    I solved my issue by doing this:

    • cut the entire main (CTRL X) out of the class (just for a few seconds),
    • save the class file (CTRL S)
    • paste the main back exactly at the same place (CTRL V)

    Strangely it started working again after that.

    0 讨论(0)
  • 2020-12-05 04:58

    It is possible to have 2 groovy-xxx-all.jar files by excample in lib directory. which makes that an app is not running

    0 讨论(0)
  • 2020-12-05 05:00

    Another tip: I initialized static fields in a wrong order - surprisingly it didn't bring up a Problem (NullPointerException?), instead Eclipse complained with exactly the message OP posted. Correcting the static initialization order made the class run-able. Example:

    private static ScriptEngineManager factory = null;
    private static ScriptEngine engine = null;
    static {
        engine = factory.getEngineByName("JavaScript");
        // factory is supposed to initialize FIRST
        factory = new ScriptEngineManager();
    }
    
    0 讨论(0)
  • 2020-12-05 05:01

    Note: This worked in the past and I received many up votes. Perhaps this is not a solution anymore - but it once was - as the eclipse version was indicated.


    Problem

    This can also be caused by a Java Build Path Problem.

    In my case, I had a an error:

    A cycle was detected in the build path of project {project}. The cycle consists of projects {x, y, z}.

    This can occur when you include other projects in the build path of the project you wish to run. In fact, all the projects will fail to run with the error Could not find the main class: Example.class


    Solution

    Open

    Windows -> Preferences -> Java-> Compiler -> Building -> Build Path Problems

    Uncheck the Abort build when build path errors occur toggle

    This seems like a can of worms if you end up with other build path errors I image. So use with caution.


    • Note: This only works if you have a "cycle error". This error message can be found in the "Markers" tab

    I found the solution to this here


    Info

    • Java 1.8.0_152
    • Eclipse Photon (June 2018)
    0 讨论(0)
  • 2020-12-05 05:01

    I had this issue after upgrading to the Eclipse 2019-12 release. Somehow the command line to launch the JVM got too long and I had to enable the jar-classpath option in the run configuration (right click on file -> run as -> run configs).

    0 讨论(0)
  • 2020-12-05 05:03

    I had this same problem in a Maven project. After creating the src/test/java folder within the project the error went away.

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