不知道这是什么问题,运行出错

arsaluo 2007-05-15 11:05:20
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;

}
...全文
344 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
li_d_s 2007-05-15
  • 打赏
  • 举报
回复
运行出错,Exception信息呢?搞得一堆人在猜错误原因
arsaluo 2007-05-15
  • 打赏
  • 举报
回复
SystemInformation是类名 不是对象名 如果是对象名编译就通不过了
fancuixia 2007-05-15
  • 打赏
  • 举报
回复
抽象类不能创建实例, 所以SystemInformation.getTCPServerPortNum();不能执行。
arsaluo 2007-05-15
  • 打赏
  • 举报
回复
那我使用的时候这么写可以吗?

tcpServerPortNum = SystemInformation.getTCPServerPortNum();

SystemInformation为此抽象类的名字
tomkai 2007-05-15
  • 打赏
  • 举报
回复
这个方法没有问题啊
chengchaog 2007-05-15
  • 打赏
  • 举报
回复
这个是在抽象类中写的 会不会是这个问题?
------------------------------
没问题,可以有方法实现,看看jdk没问题不
约翰羊 2007-05-15
  • 打赏
  • 举报
回复
调试没问题啊
arsaluo 2007-05-15
  • 打赏
  • 举报
回复
这个是在抽象类中写的 会不会是这个问题?
li_d_s 2007-05-15
  • 打赏
  • 举报
回复
错误信息呢
arsaluo 2007-05-15
  • 打赏
  • 举报
回复
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;

}
arsaluo 2007-05-15
  • 打赏
  • 举报
回复
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;

}

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧