本帖最后由 近夜之星 于 2013-11-21 22:52 编辑
按照毕老师视频中例子敲代码运行不正常,求解答- package day23;
- import java.net.*;
- class UdpSend
- {
- public static void main(String[] args) throws Exception
- {
- DatagramSocket ds = new DatagramSocket();
- byte[] buf = "udp ge men lai le".getBytes();
- DatagramPacket dp =
- new DatagramPacket(buf,buf.length,InetAddress.getByName("192.168.1.104"),10000);
-
- ds.send(dp);
- ds.close();
- }
- }
- class UdpRece
- {
- public void static main(String[] args) throws Exception
- {
- DatagramSocket ds = new DatagramSocket(10000);
- byte[] buf = new byte[1024];
- DatagramPacket dp = new DatagramPacket(buf,buf.length);
- ds.receive(dp);
- String ip = dp.getAddress().getHostAddress();
- String data = new String(dp.getData(),0,dp.getLength());
- int port = dp.getPort();
- System.out.println(ip+"::"+data+"::"+port);
- ds.close();
-
- }
- }
复制代码 编译UdpDemo能通过,接下来运行UdpSend或UdpRece均报出类似异常:- C:\Users\FengGJ\workspace\Heima\src\day23>java UdpSend
- Exception in thread "main" java.lang.NoClassDefFoundError: UdpSend (wrong name:
- day23/UdpSend)
- 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)
复制代码 |