zoukankan      html  css  js  c++  java
  • ClassNotFoundException

    在 java socket 通信,使用 ObjectInputStream 的 readObject 时, 出现了问题。

    ServerProject 问题描述是这样的: 

    java.lang.ClassNotFoundException: com.tan.mychatting.domain.User
        at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:270)
        at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:625)
        at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1612)
        at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1517)
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771)
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350)
        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:370)
        at com.YQServer.<init>(YQServer.java:24)
        at com.YQServer.main(YQServer.java:11)

    为什么会出现 java.lang.ClassNotFoundException 呢, 原因是在 ServerProject 上没有找到 User, 

    com.tan.mychatting.domain.User 

    但在 ServerProject 确实存在 User。仔细检查了一下,发现在 Client 上 User 的包名 com.tan.mychatting.domain.User , 而 Server 上包名不一样, 将包名改为一致的,问题解决。

    要传输的类必须在客户端和服务器端包名保持一致

  • 相关阅读:
    UVA 10564 Paths through the Hourglass DP
    HDU 3397 Sequence operation 线段树 成段更新 区间合并
    HDU 3308 LCIS 线段树 单点更新+区间合并
    POJ 3667 Hotel 线段树 区间合并
    UVALive 3942 Remember the Word Tire+DP
    POJ 1703 Find them, Catch them
    UVA 1366 Martian Mining DP
    UVA 1456 Cellular Network 贪心+DP
    UVA 11573 Ocean Currents
    【ACM】hdu_zs1_1003_放大的X _201307271557
  • 原文地址:https://www.cnblogs.com/tanhehe/p/3618341.html
Copyright © 2011-2022 走看看