运行代码时出现java.lang.NullPointerException如何解决?
运行代码时出现java.lang.NullPointerException如何解决?如下:
public class Server
{
public static void main(String args[])
{
ServerSocket server=null;
Socket you=null;
while(true)
{
try
{
server=new ServerSocket(6666);
//you=new Socket();
}
catch(IOException e1)
{
System.out.println("正在监听");
}
try {
you=server.accept();
InetAddress address=you.getInetAddress();
System.out.println("客户端的IP:"+address);
}
catch (IOException e)
{
}
if(you!=null)
{
new Server_thread(you).start();
}
else {
continue;
}
}
}
}
运行的如下图:
正在监听
Exception in thread "main" java.lang.NullPointerException
at Server.main(Server.java:35)