高手来看看我这段代码,应该怎么改!

zplora 2006-07-03 04:53:28
我现在在做一个聊天室,下面这个是我写的一个注册窗口的代码
class OKLst implements ActionListener
{
public void actionPerformed(ActionEvent ecv)
{
try
{
client = new Socket("127.0.0.1",1001);
toServer = new ObjectOutputStream(client.getOutputStream());
//Data sData = new Data();
String sName = txtname.getText();
String sPwd = txtpwd.getText();
String sQQ = txtqq.getText();
String sMail = txtMail.getText();
String sSex = txtsex.getText();
System.out.println(sName);
toServer.writeObject(sName+":"+sPwd+":"+sQQ+":"+sSex+":"+sMail);
}
catch(Exception ex)
{
System.out.println(ex.toString());
}
}
}

这个是服务器接受用户信息的代码
class AcceptData extends Thread
{
Socket client;
ObjectInputStream ois;
public void run()
{
try
{
ois=new ObjectInputStream(client.getInputStream());


while(true)
{

String ss = (String)ois.readObject();
System.out.println(ss);
if(ss!=null)
{


FileOutputStream fos;
fos=new FileOutputStream("D:\\chatroom\\data.dat",true);


OutputStreamWriter osw;
osw=new OutputStreamWriter(fos);

BufferedWriter bw;
bw=new BufferedWriter(osw);

//String sDt=name+":"+pwd+":"+qq+":"+sex+":"+mail;

bw.write(ss,0,ss.length());
bw.newLine();

//(3)关闭撤消通道
bw.close();
osw.close();
fos.close();
}
sleep(1000);
}
}
可是我编译没有错误
但在发送用户信息的时候,出现错误
java.lang.ClassCastException
java.lang.NullPoitnerException
...全文
150 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
dashi 2007-03-22
  • 打赏
  • 举报
回复
String ss = (String)ois.readObject(); 类型转换问题吧, 这样能输出吗? String ss = ois.readObject() + ""; System.out.println(ss);
kevinliuu 2006-07-03
  • 打赏
  • 举报
回复
ois=new ObjectInputStream(client.getInputStream());

打印一下这个ois对象,看看是否得到
zplora 2006-07-03
  • 打赏
  • 举报
回复
不行喔
还是接受不到数据
zplora 2006-07-03
  • 打赏
  • 举报
回复
就是不能输出啊
我试试你这个
linshaojie 2006-07-03
  • 打赏
  • 举报
回复
String ss = (String)ois.readObject();
类型转换问题吧, 这样能输出吗?

String ss = ois.readObject() + "";
System.out.println(ss);
zplora 2006-07-03
  • 打赏
  • 举报
回复
String ss = (String)ois.readObject();
System.out.println(ss);
接受不到发送过拉的数据
我输出不来
kevinliuu 2006-07-03
  • 打赏
  • 举报
回复
up

异常有行号,看看相应行号的位置即能确定错误

23,404

社区成员

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

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