【问题标题】:Running java class from terminal throws exception从终端运行java类抛出异常
【发布时间】:2016-12-25 13:45:30
【问题描述】:

我正在编写客户端 (android) 服务器 (java) 应用程序。在客户端和服务器中,我都在使用我在第三个项目中创建的一些类并将其作为 .jar 文件导入。当我从 Eclipse 运行服务器端时,一切正常,但是如果我使用 (java className &) 从终端运行 .class 文件,我开始得到 ​​p>

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();
    }

我假设二进制文件没有正确构建或其他什么?

【问题讨论】:

标签: java android sockets jar binary


【解决方案1】:

我发现了问题。在 Eclipse 中,我需要将我的项目导出为 Runanble JAR 文件并检查所有库是否都应该进入这个 JAR。 – Domen Jakofčič

【讨论】:

    猜你喜欢
    • 2015-04-14
    • 2012-03-03
    • 1970-01-01
    • 1970-01-01
    • 2011-02-07
    • 2011-10-21
    • 1970-01-01
    • 2010-12-06
    • 1970-01-01
    相关资源
    最近更新 更多