问题描述
- android写个注册程序时报java.io.StreamCorruptedException
-
求大神帮忙看一看,困了好久了,还是解决不了,先上点代码
public void onClick(View v) {
if (!userpassword1.getText().toString()
.equals(userpassword2.getText().toString())) {Toast.makeText(RegActivity.this, "密码不一致!", Toast.LENGTH_LONG) .show(); return; } Socket socket = null; try { socket = new Socket(Tools.IP, Tools.PORT_1); ObjectOutputStream oout = new ObjectOutputStream( socket.getOutputStream()); ObjectInputStream oin = new ObjectInputStream( socket.getInputStream()); Message m1 = new Message(); Hashtable table = new Hashtable(); table.put("userid", useridText.getText().toString()); if (manb.isChecked()) { table.put("sex", "男"); } else { table.put("sex", "女"); } table.put("username", usernameText.getText().toString()); table.put("age", userageText.getText().toString()); table.put("userpassword", userpassword1.getText().toString()); m1.setValue(table); m1.setType(m1.REG); oout.writeObject(m1); oout.flush(); m1 = (Message) oin.readObject(); if (m1.getReturnValue().get("message").toString() .equalsIgnoreCase("ok")) { AlertDialog.Builder bb = new AlertDialog.Builder( RegActivity.this); bb.setTitle("恭喜您,注册成功!"); bb.setMessage("您的ID是:" + m1.getReturnValue().get("userid")); final String userid = m1.getReturnValue().get("userid") .toString(); bb.setNeutralButton("马上登录", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent in = new Intent(); in.setClass(RegActivity.this, LoginActivity.class); in.putExtra("userid", userid); startActivity(in); RegActivity.this.finish(); } }); bb.setNegativeButton("退出", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { System.exit(0); } }); bb.create().show(); } else { Toast.makeText( RegActivity.this, "注册失败!" + m1.getReturnValue().get("message") .toString(), Toast.LENGTH_LONG) .show(); } } catch (Exception e) { e.printStackTrace(); Toast.makeText(RegActivity.this, "网络不通!"+e.getMessage(), Toast.LENGTH_LONG) .show(); } finally { try { socket.close(); } catch (IOException e) { } } }
在try...catch那捕捉的异常是null;
不知道是不是自己写的服务器的问题,还是软件中的代码错误
报的警告是
java.io.StreamCorruptedException
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1700)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1653)
at com.erhuo.login.RegActivity$SubmitButtonOnClickListener.onClick(RegActivity.java:88)这里对应的那一行是 m1 = (Message) oin.readObject();
时间: 2024-09-21 16:58:15