技术求教:java 对象序列化后,可传送对象至服务端,返回数据到客户端时抛出异常。客户端代码(界面用VE生成):
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowEvent;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.net.Socket;import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;import org.dyno.visual.swing.layouts.Constraints;
import org.dyno.visual.swing.layouts.GroupLayout;
import org.dyno.visual.swing.layouts.Leading;
//VS4E -- DO NOT REMOVE THIS LINE!
public class Student_welcome extends JFrame {
private static final long serialVersionUID = 1L;
private JLabel jLabel0;
private JLabel jLabel1;
private JTextArea jTextArea0;
private JScrollPane jScrollPane0;
private JTextArea jTextArea1;
private JScrollPane jScrollPane1;
private JLabel jLabel2;
private JButton jButton1;
private JButton jButton0;
private JLabel jLabel3;
private JButton jButton2;
private DataInputStream fromServer;
private ObjectOutputStream toServer;
private static final String PREFERRED_LOOK_AND_FEEL = "javax.swing.plaf.metal.MetalLookAndFeel";
public Student_welcome() {
try {
Socket socket =new Socket("localhost",2005);
ObjectOutputStream toServer = new ObjectOutputStream(socket.getOutputStream());
DataInputStream fromServer = new DataInputStream(socket.getInputStream());
} catch (IOException e) {
System.err.println(e);
}
initComponents();
} private void initComponents() {
setTitle("学生信息管理系统");
setLayout(new GroupLayout());
add(getJLabel0(), new Constraints(new Leading(65, 10, 10), new Leading(62, 12, 12)));
add(getJLabel1(), new Constraints(new Leading(119, 12, 12), new Leading(95, 10, 10)));
add(getJScrollPane0(), new Constraints(new Leading(181, 184, 10, 10), new Leading(60, 23, 12, 12)));
add(getJScrollPane1(), new Constraints(new Leading(181, 184, 12, 12), new Leading(94, 23, 10, 10)));
add(getJLabel2(), new Constraints(new Leading(9, 12, 12), new Leading(15, 10, 10)));
add(getJButton1(), new Constraints(new Leading(282, 83, 12, 12), new Leading(153, 23, 12, 12)));
add(getJButton0(), new Constraints(new Leading(137, 83, 10, 10), new Leading(153, 23, 12, 12)));
add(getJLabel3(), new Constraints(new Leading(268, 10, 10), new Leading(26, 12, 12)));
add(getJButton2(), new Constraints(new Leading(375, 10, 10), new Leading(23, 21, 12, 12)));
setSize(464, 203);
} private JButton getJButton2() {
if (jButton2 == null) {
jButton2 = new JButton();
jButton2.setText("注  册");
jButton2.addMouseListener(new MouseAdapter() {

public void mouseClicked(MouseEvent event) {
jButton2MouseMouseClicked(event);
}
});
}
return jButton2;
} private JLabel getJLabel3() {
if (jLabel3 == null) {
jLabel3 = new JLabel();
jLabel3.setText("还没有账号?点击");
}
return jLabel3;
} private JButton getJButton0() {
if (jButton0 == null) {
jButton0 = new JButton();
jButton0.setText("登   陆");
jButton0.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent event) {
try {
String id = jTextArea0.getText().trim();
String password = jTextArea1.getText().trim();
Student_welcome_info s =new Student_welcome_info(id,password);
toServer.writeObject(s);
toServer.flush();
boolean b = fromServer.readBoolean();
if (b==true) {
new Student_info();
this.setVisible(false);
}
} catch (Exception e) {
e.printStackTrace();
}

} private void setVisible(boolean b) {
// TODO Auto-generated method stub

}
});
}
return jButton0;
} private JButton getJButton1() {
if (jButton1 == null) {
jButton1 = new JButton();
jButton1.setText("退   出");
jButton1.addMouseListener(new MouseAdapter() {

public void mouseClicked(MouseEvent event) {
jButton1MouseMouseClicked(event);
}
});
}
return jButton1;
} private JLabel getJLabel2() {
if (jLabel2 == null) {
jLabel2 = new JLabel();
jLabel2.setText("Hi,同学欢迎使用本系统!祝您愉快...");
}
return jLabel2;
} private JScrollPane getJScrollPane1() {
if (jScrollPane1 == null) {
jScrollPane1 = new JScrollPane();
jScrollPane1.setViewportView(getJTextArea1());
}
return jScrollPane1;
} private JTextArea getJTextArea1() {
if (jTextArea1 == null) {
jTextArea1 = new JTextArea();
jTextArea1.setText("");
}
return jTextArea1;
} private JScrollPane getJScrollPane0() {
if (jScrollPane0 == null) {
jScrollPane0 = new JScrollPane();
jScrollPane0.setViewportView(getJTextArea0());
}
return jScrollPane0;
} private JTextArea getJTextArea0() {
if (jTextArea0 == null) {
jTextArea0 = new JTextArea();
jTextArea0.setText("");
}
return jTextArea0;
} private JLabel getJLabel1() {
if (jLabel1 == null) {
jLabel1 = new JLabel();
jLabel1.setText("密   码:");
}
return jLabel1;
} private JLabel getJLabel0() {
if (jLabel0 == null) {
jLabel0 = new JLabel();
jLabel0.setText("用户ID(学号):");
}
return jLabel0;
} private static void installLnF() {
try {
String lnfClassname = PREFERRED_LOOK_AND_FEEL;
if (lnfClassname == null)
lnfClassname = UIManager.getCrossPlatformLookAndFeelClassName();
UIManager.setLookAndFeel(lnfClassname);
} catch (Exception e) {
System.err.println("Cannot install " + PREFERRED_LOOK_AND_FEEL
+ " on this platform:" + e.getMessage());
}
}
/**
 * Main entry of the class.
 * Note: This class is only created so that you can easily preview the result at runtime.
 * It is not expected to be managed by the designer.
 * You can modify it as you like.
 */
public static void main(String[] args) {
installLnF();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
Student_welcome frame = new Student_welcome();
frame.setDefaultCloseOperation(Student_welcome.EXIT_ON_CLOSE);
frame.setTitle("MySchoolClient");
frame.getContentPane().setPreferredSize(frame.getSize());
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
} private void jButton1MouseMouseClicked(MouseEvent event) {
System.exit(0);
} private void windowFocusWindowLostFocus(WindowEvent event) { } private void jButton2MouseMouseClicked(MouseEvent event) {
new Student_register();
this.setVisible(false);
}
}
服务端代码:import java.io.*;
import java.net.*;
public class Student_server {
public static void main(String[] args) {
new Student_server(); } private ObjectOutputStream outpuToClient;
private ObjectInputStream inputFromClient;

public Student_server() {
try {
ServerSocket serverSocket = new ServerSocket(2005);
System.out.println("Server started!");
while (true) {
Socket socket = serverSocket.accept();
inputFromClient = new ObjectInputStream(socket.getInputStream());
outpuToClient = new ObjectOutputStream(socket.getOutputStream());
Student_welcome_info s =(Student_welcome_info) inputFromClient.readObject();
if (s.getIdString()=="09008312"&&s.getPasswordsString()=="09008312") {
outpuToClient.writeBoolean(true) ;
}
System.out.println("It's OK");
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
} finally {
try {
inputFromClient.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
}抛出异常:java.lang.NullPointerException
at Student_welcome$2.mouseClicked(Student_welcome.java:98)
at java.awt.AWTEventMulticaster.mouseClicked(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)小弟初学,搞不太明白,想各位大神求教!!!