在 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 上包名不一样, 将包名改为一致的,问题解决。

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

ClassNotFoundException的更多相关文章

  1. ClassNotFoundException: org.apache.catalina.loader.DevLoader 自己摸索,丰衣足食

    使用tomcat插件时遇到的问题: ClassNotFoundException: org.apache.catalina.loader.DevLoader 解决方案: 参考了许多文章,对我自己的目录 ...

  2. 【异常】Caused by: java.lang.ClassNotFoundException: org.springframework.dao.DataIntegrityViolationException

    Caused by: java.lang.ClassNotFoundException: org.springframework.dao.DataIntegrityViolationException ...

  3. MaxTemperature程序Mapper ClassNotFoundException

    错误: 执行hadoop权威指南上MaxTemperature程序出现Mapper类ClassNotFoundException异常: 解决: 将书上的 JobConf job = new JobCo ...

  4. 真正解决问题:maven eclipse tomcat java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener--转

    原文地址:http://www.cnblogs.com/amosli/p/4067665.html 在使用eclipse进行整合springmvc时经常会碰到这样的异常: java.lang.Clas ...

  5. Struts2环境下Tomcat启动异常:Exception starting filter struts2,报了一个java.lang.ClassNotFoundException

    在写一个struts2+hibernate整合的小例子时,启动Tomcat服务器,报了一个: 严重: Exception starting filter struts2java.lang.ClassN ...

  6. JAVA类的静态加载和动态加载以及NoClassDefFoundError和ClassNotFoundException

    我们都知道Java初始化一个类的时候可以用new 操作符来初始化, 也可通过Class.forName()的方式来得到一个Class类型的实例,然后通过这个Class类型的实例的newInstance ...

  7. maven 项目启动tomcat报错 java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

    maven项目启动tomcat报错: java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderLi ...

  8. NoClassDefFoundError vs ClassNotFoundException

    我们先来认识一下Error 和Exception, 两个都是Throwable类的直接子类.  Javadoc 很好的说明了Error类: An Error is a subclass of Thro ...

  9. maven ClassNotFoundException: org.springframework.web.context.ContextLoaderL

    信息: Starting Servlet Engine: Apache Tomcat/6.0.32 2012-3-31 9:39:40 org.apache.catalina.core.Standar ...

  10. eclipse java项目中明明引入了jar包 为什么项目启动的时候不能找到jar包 项目中已经 引入了 com.branchitech.app 包 ,但时tomcat启动的时候还是报错? java.lang.ClassNotFoundException: com.branchitech.app.startup.AppStartupContextListener java.lang.ClassN

    eclipse java项目中明明引入了jar包 为什么项目启动的时候不能找到jar包 项目中已经 引入了 com.branchitech.app 包 ,但时tomcat启动的时候还是报错?java. ...

随机推荐

  1. Linux终端Ctrl相关快捷键

    快速跳至行首:Ctrl+A 快速跳至行尾:Ctrl+E 向前删除至行首:Ctrl+U 向后删除至行尾:Ctrl+K 向后删一个单词:Ctrl+D 清屏:Crtl+L(clear)

  2. Entity Framework Demo(一) 简单搭建环境

    Entity Framwork(实体框架,简称EF)是ORM(Object Relational Mapping,对象映射关系)的一个解决方案. EF允许项目将数据库的表映射为实体,并封装了操作方法, ...

  3. 百度知道的php爬虫

    原文地址:百度知道的php爬虫作者:好宏杰软件 <?php class spider  {    private $content ;    private $contentlen ;    p ...

  4. js 连续赋值

    无意中网上发现的这个问题,预想的结果和真实的结果大相径庭. var a={n:1} var b=a; a.x=a={n:2} console.log(a.x); console.log(b.x); u ...

  5. PHP 数组转字符串,与字符串转数组

    implode 使用一个字符串将数组变成字符串 <?php $array = array('lastname', 'email', 'phone'); $comma_separated = im ...

  6. 将应用程序中的一些参数写到xml配置文件中

    最近碰到一个问题,需要将程序中的一些基本参数写到xml文件中,虽然网上有好多现成的代码,但是觉得对xml不熟悉,果断就研究了一下.先说一下大体思路吧,我设计了一个用来读取和回填的类,然后定义了一个接口 ...

  7. 样式 style="clear:both"

    <div style="clear:both"></div>clear:both该属性的值指出了不允许有浮动对象的边.通俗的讲:这段代码的做用是:清除同行元 ...

  8. SQL SERVER 高级编程 - 自定义函数 拾忆

    每个人都很忙,但是花10分钟复习下,总结下基础东西还是很有益处的. 背景: 总结一句,使用简便,还能递归,是的SQL更简洁,相对比一大堆的关联语句,而且关联一大堆还不一定实现特定功能.而且共用部分可以 ...

  9. 快速消除IOS 版本升级带来的警告

    开发中我们经常会遇到这样的情况,我们在IOS 6.0开发的程序,当出现IOS 7.0 或者IOS8.0的时候,我们代码中得某些方法苹果已经不推荐使用了,建议我们改用新的方法.如果我们不更新方法,则会出 ...

  10. [Lua]基于cc.load('mvc') .ViewBase索引资源方案

    local MainScene = class("MainScene", cc.load("mvc").ViewBase) MainScene.RESOURCE ...