import java.net.InetAddress;
import java.net.UnknownHostException;
class IpAddr {
public static void main(String arg[]) {
System.out.println("Hello Jagadeesh...>!!");
try {
InetAddress ia=InetAddress.getByName("www.facebook.com");
System.out.println(ia);
}
catch(UnknownHostException uhe) {
System.out.println("ip address of facebook is not found. :(");
}
}
}
在控制台中:运行时E:\ myworkspace \ network_practice \ src \ stage1> javac IpAddr.javaE:\ myworkspace \ network_practice \ src \ stage1> java IpAddr
Exception in thread "main" java.lang.NoClassDefFoundError: IpAddr
(错误名称:stage1 / IpAddr)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
E:\myworkspace\network_practice\src\stage1>cd..
您没有在您的类中声明一个程序包,所以它转到默认程序包。但是您有stage1文件夹。
没有Java虚拟机时Java中出现NoClassDefFoundError能够在运行时找到一个特定的类编译时间。
来源:http://javarevisited.blogspot.de/2011/06/noclassdeffounderror-exception-in.html
因此,我会检查您是否已将所有必要的内容添加到类路径中。
Jagadeesh,可能是您的InetAddress jar版本可能不受支持的情况