| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 984 人关注过本帖
标题:求助程序调试出错提示 java.lang.NullPointerException
只看楼主 加入收藏
lbqxl0122
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-5-1
收藏
 问题点数:0 回复次数:1 
求助程序调试出错提示 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"

查了好久了,就是不知错在哪,请大家帮忙看看.
搜索更多相关主题的帖子: java lang 服务器 提示 
2008-07-30 21:43
msi110
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2008-4-15
收藏
得分:0 
应该是
server = new ServerSocket(4331);
这句有错吧。
ServerSocket的参数应该是Socket类型的,不能直接写成4331。把它转换成Socket应该就可以了吧。
你试试·····
2008-08-16 18:57
快速回复:求助程序调试出错提示 java.lang.NullPointerException
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023089 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved