Exception in thread “main” java.lang.NoClassDefFoundError: HelloWorld

前端 未结 4 1385
长情又很酷
长情又很酷 2020-12-13 11:46

I\'ve been working on this for about an hour and thumbing through Q&As on stackoverflow but I haven\'t found a proposed solution to my problem. I\'m sorry if this is a d

4条回答
  •  醉梦人生
    2020-12-13 12:10

    As a beginner you might encounter a very similar scenario where the error output is the same. You try to compile and run your simple program(without having any package set) and you do this:

    javac HelloWorld.java
    java HelloWorld.class
    

    This will give you the same java.lang.NoClassDefFoundError since java thinks HelloWorld is your package and class your class name. To solve it just use

    javac HelloWorld.java
    java HelloWorld
    

    See the Java page - Lesson: Common Problems (and Their Solutions)

提交回复
热议问题