我在运行程序时,出现如下错误提示,请问如何解决?谢谢!
java.io.EOFException
at java.io.ObjectInputStream$PeekInputStream.readFully(Unknown Source)
at java.io.ObjectInputStream$BlockDataInputStream.readShort(Unknown Source)
at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
at java.io.ObjectInputStream.<init>(Unknown Source)
at com.bj.client.Client.read(Client.java:118)
at com.bj.client.Client.send(Client.java:92)
at com.bj.client.view.UserView.login(UserView.java:76)
at com.bj.client.view.UserView.start(UserView.java:39)
at com.bj.client.view.StartMain.main(StartMain.java:13)
相关代码如下,read()方法是将对象流中的内容读入出,并封装到Command实例中,其中错误是在第8行产生的“in=new ObjectInputStream(client.getInputStream());”,client是Socket实例。
Java code
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
public Command<?> read()
{
Command<?> cmd=null;
ObjectInputStream in = null;
try {
in=new ObjectInputStream(client.getInputStream());
cmd=(Command<?>)in.readObject();
return cmd;
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
finally
{
if(in!=null)
{
try {
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
} |
|