Exception in thread "main" java.lang.NullPointerExceptionat Server.main(Server.java:33)
来源:百度知道 编辑:UC知道 时间:2024/06/22 08:11:31
import java.io.*;
import java.net.*;
import java.util.*;
class FileName implements FilenameFilter
{
String str=null;
FileName (String s)
{
str="."+s;
}
public boolean accept(File dir,String name)
{
return name.endsWith(str);
}
}
public class Server
{
public static void main(String args[])
{
ServerSocket server=null;
Socket you=null;
while(true)
{
try
{
server=new ServerSocket(6666);
}
catch(IOException e1)
{
System.out.println("正在监听");
}
try {
you=server.accept();
InetA
import java.net.*;
import java.util.*;
class FileName implements FilenameFilter
{
String str=null;
FileName (String s)
{
str="."+s;
}
public boolean accept(File dir,String name)
{
return name.endsWith(str);
}
}
public class Server
{
public static void main(String args[])
{
ServerSocket server=null;
Socket you=null;
while(true)
{
try
{
server=new ServerSocket(6666);
}
catch(IOException e1)
{
System.out.println("正在监听");
}
try {
you=server.accept();
InetA
you=server.accept(); 这句话出的异常
原因可能是你启动了2个服务器端,而后虽然你处理了第一个异常,就是IOException e1,就是端口被占用,但程序依然向下执行到you=server.accept(); . 所以抛出 java.lang.NullPointerExceptionat
修改方法 : 程序改为
while(true)
{
try
{
server=new ServerSocket(6666);
} catch(BindException e)
{
System.out.println("端口使用中");
System.out.println("请关掉相关程序并重新运行服务器");
System.exit(0);
} catch (IOException e) {
e.printStackTrace();
}
Exception EOleSysError in module
英语作文,主题:in th park
Realistic novel in the 18th century
on June 5th和in June
Christmas in the 13th Month
nothing in thé world 是什么意思?
Report ranks China 6th in overall strength 怎么翻译?
谁能告诉我feminism in 17th century 在英国
The film was released on 11th July in China
Fashions in America before the 19th century_____those of Egland.