Eclipse can't find / load main class

前端 未结 20 2197
猫巷女王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 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();
    }
    

提交回复
热议问题