开发者

unable to run a java program on mac

开发者 https://www.devze.com 2023-04-06 00:35 出处:网络
I am trying to run a java program which is in a package named udpprobe.client but I am unable to run the program. It compiles all good but then I get the error:

I am trying to run a java program which is in a package named udpprobe.client but I am unable to run the program. It compiles all good but then I get the error:

Exception in thread "main" java.lang.NoClassDefFoundError: UDPClient (wrong name: udpprobe/client/UDPClient)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
    at java.security.SecureClassLoader.defineClass(SecureClassLoade开发者_运维知识库r.java:141)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)

Could someone help me with the setup of the classpath thing. I'm working on a mac. Thanks


This error occurs typically when you are trying to start a program from the directory the class file is contained in as opposed to the base of the package.

In your case, you have a directory:

/some/path/to/udpprobe/client/

With a:

UDPClient.class

file and possibly also a:

UDPClient.java

file. You'll get that error if you UDPClient.java specifies a package of udpprobe.client and you try to execute it from it's own directory like this:

/some/path/to/udpprobe/client$ java UDPClient

However, if you go to the base directory of the package and execute the fully qualified name, it should work:

/some/path/to$ java udpprobe.client.UDPClient

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号