public static int getTCPServerPortNum()
{
int num = 0;///调试在此出错
String host = "localhost";
for (int i = 1; i < 65536; i++)
{
try
{
Socket s = new Socket(host, i);
}
catch (UnknownHostException ex)
{
System.err.println(ex);
break;// it is not a server port
}
catch (IOException e)
{
e.printStackTrace();
break;// it is not a server port
}
num++;
}
return num; }

解决方案 »

  1.   

    这个是在抽象类中写的  会不会是这个问题?
    ------------------------------
    没问题,可以有方法实现,看看jdk没问题不
      

  2.   

    那我使用的时候这么写可以吗?tcpServerPortNum = SystemInformation.getTCPServerPortNum();SystemInformation为此抽象类的名字
      

  3.   

    抽象类不能创建实例, 所以SystemInformation.getTCPServerPortNum();不能执行。
      

  4.   

    SystemInformation是类名  不是对象名  如果是对象名编译就通不过了
      

  5.   

    运行出错,Exception信息呢?搞得一堆人在猜错误原因
      

  6.   

    public static int getTCPServerPortNum()
    {
    int num = 0;///调试在此出错
    String host = "localhost";
    for (int i = 1; i < 65536; i++)
    {
    try
    {
    Socket s = new Socket(host, i);
    }
    catch (UnknownHostException ex)
    {
    System.err.println(ex);
    break;// it is not a server port
    }
    catch (IOException e)
    {
    e.printStackTrace();
    break;// it is not a server port
    ==================================================================在这边处理错误
    }
    num++;
    }
    return num; }
    正确程序
    public static int getTCPServerPortNum()
    {
    int num = 0;
    String host = "localhost";
    for (int i = 1; i < 65536; i++)
    {
    try
    {
    Socket s = new Socket(host, i);
    }
    catch (UnknownHostException ex)
    {
    System.err.println(ex);
    break;// it is not a server port
    }
    catch (IOException e)
    {
    // it is not a server port
    }
    num++;
    }
    return num; }
      

  7.   

    public  static  int  getTCPServerPortNum()  
               {  
                           int  num  =  0;///调试在此出错  
                           String  host  =    "localhost  ";  
                           for  (int  i  =  1;  i    <  65536;  i++)  
                           {  
                                       try  
                                       {  
                                                   Socket  s  =  new  Socket(host,  i);  
                                       }  
                                       catch  (UnknownHostException  ex)  
                                       {  
                                                   System.err.println(ex);  
                                                   break;//  it  is  not  a  server  port  
                                       }  
                                       catch  (IOException  e)  
                                       {  
                                                   e.printStackTrace();  
                                                   break;//  it  is  not  a  server  port  
     
     
    ==================================================================在这边处理错误  
                                       }  
                                       num++;  
                           }  
                           return  num;  
     
               }  
     
     
     
     
     
     
     
     
    正确程序  
     
     
    public  static  int  getTCPServerPortNum()  
               {  
                           int  num  =  0;  
                           String  host  =    "localhost  ";  
                           for  (int  i  =  1;  i    <  65536;  i++)  
                           {  
                                       try  
                                       {  
                                                   Socket  s  =  new  Socket(host,  i);  
                                       }  
                                       catch  (UnknownHostException  ex)  
                                       {  
                                                   System.err.println(ex);  
                                                   break;  
                                       }  
                                       catch  (IOException  e)  
                                       {  
                                                   //  it  is  not  a  server  port  
                                       }  
                                       num++;  
                           }  
                           return  num;  
     
               }