我是有一个接收端一个是发送端,分别是两个工程,我把那个需要发送的类分别加到了两个工程中,然后接收端就会报没找到类的异常。求大家帮我看看吧!
LogCat:
01-03 07:49:46.408: D/dalvikvm(14528): Late-enabling CheckJNI
01-03 07:49:46.448: I/dalvikvm(14528): Turning on JNI app bug workarounds for target SDK version 8...
01-03 07:49:46.578: I/System.out(14528): 开始服务
01-03 07:50:18.038: D/ViewRootImpl(14708): pckname = study.message.receive
01-03 07:50:18.048: I/System.out(14708): 开始服务
01-03 07:52:08.608: I/System.out(14708): S: Error
01-03 07:52:08.608: W/System.err(14708): java.lang.ClassNotFoundException: com.example.touchevent.SaveInformation
01-03 07:52:08.618: W/System.err(14708): at java.lang.Class.classForName(Native Method)
01-03 07:52:08.618: W/System.err(14708): at java.lang.Class.forName(Class.java:217)
01-03 07:52:08.618: W/System.err(14708): at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:2297)
01-03 07:52:08.618: W/System.err(14708): at java.io.ObjectInputStream.readNewClassDesc(ObjectInputStream.java:1656)
01-03 07:52:08.618: W/System.err(14708): at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:683)
01-03 07:52:08.618: W/System.err(14708): at java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:1799)
01-03 07:52:08.618: W/System.err(14708): at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:787)
01-03 07:52:08.618: W/System.err(14708): at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1999)
01-03 07:52:08.618: W/System.err(14708): at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1956)
01-03 07:52:08.618: W/System.err(14708): at study.message.receive.Msg_REC_Background$AndroidServer.run(Msg_REC_Background.java:53)
01-03 07:52:08.618: W/System.err(14708): at java.lang.Thread.run(Thread.java:856)
01-03 07:52:08.618: W/System.err(14708): Caused by: java.lang.NoClassDefFoundError: com/example/touchevent/SaveInformation
01-03 07:52:08.618: W/System.err(14708): ... 11 more
01-03 07:52:08.618: W/System.err(14708): Caused by: java.lang.ClassNotFoundException: com.example.touchevent.SaveInformation
01-03 07:52:08.628: W/System.err(14708): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
01-03 07:52:08.628: W/System.err(14708): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
01-03 07:52:08.628: W/System.err(14708): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
01-03 07:52:08.628: W/System.err(14708): ... 11 more
这是发送端的发送代码
ObjectOutputStream ops = new ObjectOutputStream(socket.getOutputStream());
ops.writeObject(saveInformation);
这是接收端的接收代码
ObjectInputStream ois = new ObjectInputStream(client.getInputStream());
SaveInformation saveInformation = (SaveInformation) ois.readObject();
SaveInformation是我序列化的一个类。
------解决方案--------------------
具体的我也不太清楚,但是个人觉得两边这个序列化的文件包名要一样
------解决方案--------------------
点击eclipse项目右键 Export,找到jar
然后选择你要打包的类,要确保这些类之间的依赖关系。
指定一个路径就OK了