本帖最后由 闫杏荣 于 2012-6-21 14:23 编辑
按照视频中敲的代码,但不知道问题出在哪,提示- Exception in thread"main" java.lang.NoClassDefFoundError:chardemo(wrong name:udp/chardemo)
- ……
- Could not find the main class:chardemo. Program will exit.
复制代码 以下为源代码- package udp;
- import java.io.*;
- import java.net.*;
- class Send implements Runnable
- {
- private DatagramSocket ds;
- public Send(DatagramSocket ds){
- this.ds = ds;
- }
- public void run(){
- try{
- BufferedReader bur = new BufferedReader(new InputStreamReader(System.in));
- String line = null;
- while((line = bur.readLine())!=null)
- {
- if("886".equals(line))
- break;
- byte[] buf = line.getBytes();
- DatagramPacket dp = new DatagramPacket(buf,buf.length,InetAddress.getByName("127.0.0.1"),10002);
- }
- }
- catch(Exception e){
- throw new RuntimeException("发送端失败!");
-
- }
- }
- }
- class Rece implements Runnable{
- private DatagramSocket ds;
- public Rece(DatagramSocket ds){
- this.ds=ds;
- }
- public void run(){
- try{
- while(true){
- 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());
- System.out.println(ip+":"+data);
- }
- }
- catch(Exception e){
- throw new RuntimeException("接收端失败!");
-
- }
- }
- }
- public class chardemo {
- /**
- * @param args
- */
- public static void main(String[] args) throws Exception{
- // TODO Auto-generated method stub
- DatagramSocket sendSocket= new DatagramSocket();
- DatagramSocket receSocket = new DatagramSocket(1567);
-
- new Thread(new Send(sendSocket)).start();
- new Thread(new Rece(receSocket)).start();
- }
- }
复制代码 求火眼晶晶~~~~~~~
|
|