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

做~自己de王妃 提交于 2019-12-24 03:25:04

问题


This is my first project with Java. I'm using Ubuntu.

I'm in the folder /home/anis/jtest/myProject and I run the Hello.java file with :

javac src/org/example/Hello.java

Seems that works. I get no error and a Hello.class file in the example directory.

Then from the myProject firectory again I run :

java -cp src/org/example Hello

and I get the error : Exception in thread "main" java.lang.NoClassDefFoundError: Hello (wrong name: org/example/Hello)

My code for Hello.java is :

package org.example;

public class  Hello  {
        public static void main(String[] args)  {
            System.out.println("Hello\n");
    }
}

回答1:


In folder src/:

$ javac org/example/Hello.java
$ java org.example.Hello


来源:https://stackoverflow.com/questions/22431904/exception-in-thread-main-java-lang-noclassdeffounderror-hello

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!