我正在编写客户端(android)服务器(java)应用程序。在客户端和服务器中,我使用了我在第三个项目中创建的一些类,并将其导入为.jar文件。当我从eclipse运行服务器端时一切正常,但是如果我从终端运行.class文件(java className&)我开始得到
java.io.StreamCorruptedException:无效的类型代码:2E
当服务器应该读取从.jar文件导入的对象时。
在服务器端读取提交数据的代码:
try (
ObjectOutputStream outToClient = new ObjectOutputStream(socket.getOutputStream());
ObjectInputStream inFromClient = new ObjectInputStream(socket.getInputStream());
) {
String inputLine, outputLine;
checkClientStatus(outToClient);
Object p;
for(;;) {
p = inFromClient.readObject();
if(p instanceof String){
String s = (String) p;
if(s.equals("pong")) {
isClientAlive = true;
System.out.println("pong");
}else{
System.out.println("You said:"+s);
outToClient.writeObject("You said:"+s);
}
}else if(p instanceof Position){
System.out.println("pozicija");
}
}
}catch (SocketTimeoutException exc){
// you got the timeout
}catch (EOFException exc){
try {
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
// end of stream
}catch (IOException exc){
// some other I/O error: print it, log it, etc.
exc.printStackTrace(); // for example
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
我假设二进制文件没有正确构建或者什么?
答案 0 :(得分:0)
我发现了问题。在eclipse中,我需要将我的项目导出为Runanble JAR文件,并检查是否所有库都应放入该JAR中。 – DomenJakofčič