How to solve java.lang.NoClassDefFoundError?

前端 未结 27 2229
暗喜
暗喜 2020-11-21 06:04

I\'ve tried both the example in Oracle\'s Java Tutorials. They both compile fine, but at run-time, both come up with this error:

Exception in thread \"main\"         


        
27条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-21 06:39

    If your project is in a package like com.blahcode and your class is called Main, the compiled files may be output in a directory structure like ./out/com/blahcode/Main.class. This is especially true for IntelliJ IDEA.

    When trying to run from a shell or cmd, you need to cd to that which contains com as a sub-directory.

    cd out
    java -classpath . com.blahcode.Main
    

提交回复
热议问题