当前位置: 代码迷 >> Java相关 >> 救命呀......救我!!!!!
  详细解决方案

救命呀......救我!!!!!

热度:294   发布时间:2005-10-06 09:31:00.0
救命呀......救我!!!!!

我的程序编译通过,但是运行时出了下面的错误: F:\>javac xyh\AppServer.java(编译通过) F:\>java xyh\AppServer.class Exception in thread "main" java.lang.NoClassDefFoundError: xyh\AppServer/class(运行出错) 求求恩人搭救我吧! 下面是我的程序: import java.io.*; import java.awt.event.*; import java.net.*;A public class AppServer { public static void main(String args[]) { new AppServer();} } class appServer extends Thread { ServerSocket server; void fail(String message,Exception e) { System.out.println(message+"."+e);} public appServer() { try { server=new ServerSocket(2876); } catch(IOException e) { fail("不能开始服务器!",e); } System.out.println("服务器开始:"); this.start(); } public void run() { try { while(true) { Socket netClient=server.accept(); Connection con=new Connection(netClient); } } catch(IOException e) { fail("不能监听到客户!",e); } } } class Connection extends Thread { protected Socket netClient; protected BufferedReader fromClient; protected PrintStream toClient; public Connection (Socket client) { netClient=client; try { fromClient=new BufferedReader(new InputStreamReader

(netClient.getInputStream())); toClient=new PrintStream(netClient.getOutputStream()); } catch(IOException e) { try{netClient.close();} catch(IOException e1) { System.out.println("不能关闭客户套接字"+e1); return; } } this.start(); } public void run() { String Message; try { for(;;) { Message=fromClient.readLine(); if(Message==null)break; toClient.println("你已登陆成功!"); System.out.println("来自客户的信息:"+Message); } } catch(IOException e) { System.out.println("读客户流异常!"+e);} finally { try{ netClient.close();} catch(IOException e) { System.out.println("不能关闭客户套接字!"+e); return; } } } } 期盼 期盼 期盼......

搜索更多相关的解决方案: 救命  

----------------解决方案--------------------------------------------------------
待会儿再看看。。。 现在还没搞好。。。呵呵 。。。
----------------解决方案--------------------------------------------------------
哎。。能力有限。。。还是没能帮你 。。。
----------------解决方案--------------------------------------------------------

Thank you all the same!


----------------解决方案--------------------------------------------------------
你的程序我也晕,看不懂。
我特地加了Dedug 来看你的程序,那个debug 确实打印了出来,
但是那个Socket 却对 toString() 函数无动于衷,
不管你用 if(netClient == null)
                 System.out.println("debug");
还是用if(netClient != null)
                 System.out.println("debug");
来测试,那个netClient 都没有反应。
不理解了。

import java.io.*;
import java.awt.event.*;
import java.net.*;
import java.nio.channels.IllegalBlockingModeException;
import java.net.SocketTimeoutException;

public class AppServer
{
  public static void main(String args[])
  {
    ApplicationServer as = new ApplicationServer();
  }
}

class ApplicationServer extends Thread
{  
  ServerSocket server;
  public void fail(String message,Exception e)
  {
    System.out.println(message+"."+e);
  }
  public ApplicationServer()
  {
    try
    {
      server=new ServerSocket(2876);
      if(server.isBound())
        System.out.println("is Bound");
    }
    catch(IOException e)
    {
      fail("不能开始服务器!",e);
    }
    System.out.println("服务器开始:");
    this.start();
  }
  public void run()
  {  
    try
    {         
      while(true)
      {
        System.out.println("debug");     // debug
        Socket netClient = server.accept();
        if(netClient.isConnected())
         System.out.println("is connected");     //Caution
        System.out.println(netClient.toString());  //Caution
        Connection con=new Connection(netClient);
      }
    }
    catch(IOException e)
    {
      fail("不能监听到客户!",e);
    }
    catch(SecurityException se)
    {
      fail("不能监听到客户!",se);
    }
    /*catch(SocketTimeoutException ste)
    {
      fail("不能监听到客户!",ste);
    }*/
    catch(IllegalBlockingModeException ibme)
    {
      fail("不能监听到客户!",ibme);
    }
  }
}

class Connection extends Thread
{  
  protected Socket netClient;
  protected BufferedReader fromClient;
  protected PrintStream toClient;
  public Connection (Socket client)
  {  
    netClient=client;
    try
    {
      
      fromClient=new BufferedReader(
        new InputStreamReader
        (netClient.getInputStream())
      );
      toClient=new PrintStream(netClient.getOutputStream());
    }
    catch(IOException e)
    {
      try
      {
        netClient.close();
      }
      catch(IOException e1)
      {
        System.out.println("不能关闭客户套接字"+e1);
        return;
      }
    }
    this.start();  
  }
  
  public void run()
  {
    String Message;
    try
    {  
      for(;;)
      {
        Message=fromClient.readLine();
        if(Message==null)
          break;
        toClient.println("你已登陆成功!");
        System.out.println("来自客户的信息:"+Message);
      }
    }
    catch(IOException e)
    {
      System.out.println("读客户流异常!"+e);
    }
    finally
    {
      try
      {
        netClient.close();
      }
      catch(IOException e)
      {
        System.out.println("不能关闭客户套接字!"+e);
        return;
      }
    }
  }
}
----------------解决方案--------------------------------------------------------
初学者看不懂             晕
----------------解决方案--------------------------------------------------------

import java.io.*; import java.awt.event.*; import java.net.*; import java.nio.channels.IllegalBlockingModeException; import java.net.SocketTimeoutException;

class appServer2 extends Thread { ServerSocket server; public void fail(String message,Exception e) { System.out.println(message+"."+e); } public appServer2() { try { server=new ServerSocket(2876); if(server.isBound()) System.out.println("is Bound"); } catch(IOException e) { fail("不能开始服务器!",e); } System.out.println("服务器开始:"); this.start(); } public void run() { try { while(true) { System.out.println("debug"); // debug Socket netClient = server.accept(); if(netClient.isConnected()) System.out.println("is connected"); //Caution System.out.println(netClient.toString()); //Caution Connection con=new Connection(netClient); } } catch(IOException e) { fail("不能监听到客户!",e); } catch(SecurityException se) { fail("不能监听到客户!",se); } /*catch(SocketTimeoutException ste) { fail("不能监听到客户!",ste); }*/ catch(IllegalBlockingModeException ibme) { fail("不能监听到客户!",ibme); } } public static void main(String args[]) //把 AppServer 合并到你所谓的 appServer { appServer2 as = new appServer2(); } } //为什么合并后 会运行出这些信息 /** * is Bound *服务器开始 *Debug * */


----------------解决方案--------------------------------------------------------
版主我用jdk运行你改后的程序怎么还是那个问题呀? tell me:Exception in thread "main" java.lang.NoClassDefFoundError: xyh\AppServer/class 到底是怎么个意思? 谢谢! 先
----------------解决方案--------------------------------------------------------
你再看一下,你是否完全Copy 了我5楼的代码?
我已经把你的那个class 名改掉了, 在你的代码中为 appServer, 我将它改为ApplicationServer
就是下面这个样子。
class ApplicationServer extends Thread

我估计这是class 名一样所造成的,虽然你将他们大小写作了区分,但是编译后会不会对大小写作区别呢?我怀疑问题就出在这里。
你的程序,在我修改后至少可以运行,但是还有问题。
我特地用了些笨办法来测试,结果却是到了
Socket netClient = server.accept(); 这一行程序就不动了,我也不懂了,只能帮到你这里了。
----------------解决方案--------------------------------------------------------

谢谢你版主 ! !

[em38]
----------------解决方案--------------------------------------------------------
  相关解决方案