求助程序调试出错提示 java.lang.NullPointerException
要求是服务器的Server2.java同过套接字将两个文件压缩后发送给客户端,客户端接受.下面程序是调试服务端有问题,客户端没问题.
Server2.java
import *;
import *;
import java.util.zip.*;
public class Server2
{
public static void main(String args[])
{
ServerSocket server = null;
ServerThread thread;
Socket you = null;
while(true)
{
try
{
server = new ServerSocket(4331);
}
catch(IOException e1)
{
System.out.println("正在监听");
}
try
{
System.out.println("等待客户呼叫");
you = server.accept();
System.out.println("客户地址:"+you.getInetAddress());
}
catch(IOException e)
{
System.out.println("正在等待客户");
}
if(you!=null)
{
new ServerThread(you).start();
}
}
}
}
class ServerThread extends Thread
{
Socket socket;
ZipOutputStream out;
String s = null;
ServerThread(Socket t)
{
socket = t;
try
{
out = new ZipOutputStream(socket.getOutputStream());
}
catch(IOException e){}
}
public void run()
{
try
{
out.putNextEntry(new ZipEntry("Example.java"));
FileInputStream reader = new FileInputStream("Example.java");
byte b[]=new byte[1024];
int n = -1;
while((n=reader.read(b,0,1024))!=-1)
{
out.write(b, 0, n);
}
out.putNextEntry(new ZipEntry("E.java"));
reader = new FileInputStream("E.java");
n = -1;
while((n = reader.read(b, 0, 1024))!=-1)
{
out.write(b, 0, n);
}
reader.close();
out.close();
}
catch(IOException e){}
}
}
总是提示:
java.lang.NullPointerException
at Server2.main(Server2.java:25)
Exception in thread "main"
查了好久了,就是不知错在哪,请大家帮忙看看.