Wednesday, March 26, 2014

Serializable problems sending and receiving way through socket


posts by tyaathome on 2013-10-11 13:04:49 Edit
I have sent a receiving end of one side, namely the two projects, I need to send that class were added to the two projects, then the receiving end will report did not find exception class. Beg you to help me find it!

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): start service
01-03 07:50:18.038: D / ViewRootImpl (14708): pckname = study.message.receive
01-03 07:50:18.048: I / System.out (14708): start service
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


This code is transmitted to the transmitting side
 
ObjectOutputStream ops = new ObjectOutputStream (socket.getOutputStream ());
ops.writeObject (saveInformation);


This is the receiving end receives the code
 
ObjectInputStream ois = new ObjectInputStream (client.getInputStream ());
SaveInformation saveInformation = (SaveInformation) ois.readObject ();


SaveInformation I serialize a class.
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
com.example.touchevent.SaveInformation this class did not find obvious errors,
You need to ensure that the server and client have this com.example.touchevent.SaveInformation.class file
Reply:
Compile time com.example.touchevent.SaveInformation to be consistent, you should be OK.
Reply:
Package name, right?
Reply:
reference to the second floor birdsaction reply:
compile time com.example.touchevent.SaveInformation to be consistent, you should be OK.

This is the sending end of the package. Then how can I do it?
Reply:
This server-side java files compiled com.example.touchevent.SaveInformation generate class files to package the class files into jar, put the client, as the client lib should be fine.
Reply:
references, 5th Floor birdsaction reply:
server side java compiler com.example.touchevent.SaveInformation This file is generated class file to package the class files into jar, into the client, as the client lib should be fine.

How packaged into a jar file it? Using eclipse or the command? I am a novice to solve
Reply:
jar command you to baidu search, is very simple.
Reply:
reference to the 7th floor birdsaction reply:
jar command you to baidu search, is very simple.

Oh, now a problem. I do not use javac and jar command. How to do?
Reply:
references, 4th Floor tyaathome reply:
Quote: references to the second floor birdsaction reply:

Compile time com.example.touchevent.SaveInformation to be consistent, you should be OK.

This is the sending end of the package. Then how can I do it?

The package should require that the sequence in which the classes in a consistent receiver and sender
Reply:
reference to the 8th floor tyaathome reply:
Quote: references to the 7th floor birdsaction reply:

jar command you to baidu search, is very simple.

Oh, now a problem. I do not use javac and jar command. How to do?

Environment variable is not equipped
Reply:
reference to the 9th floor guoyoulei520 reply:
Quote: references to the 4th floor tyaathome reply:

Quote: references to the second floor birdsaction reply:

Compile time com.example.touchevent.SaveInformation to be consistent, you should be OK.

This is the sending end of the package. Then how can I do it?

The package should be consistent with the need to serialize the class in which the recipient and sender of

How to ensure consistent?
Reply:
reference to the 7th floor birdsaction reply:
jar command you to baidu search, is very simple.

Or not ah. Jar is so loaded bag?

Reply:
Come Help me ah. The problems are two days.
Reply:
Dingding solving.
Reply:
reference to the 13th floor tyaathome reply:
Come Help me ah. The problems are two days.

Specifically, I do not know, but personally feel that both sides of the serialized file name to the same package
Reply:
cited 15 floor guoyoulei520 reply:
Quote: references to the 13th floor tyaathome reply:

Come Help me ah. The problems are two days.

Specifically, I do not know, but personally feel that both sides of the serialized file package name to be the same

QQ know you do, I ask it plus you QQ. Ask too tangled. F5 constantly get answered.
Reply:
reference to the 16th floor tyaathome reply:
Quote: 15th Floor guoyoulei520 cited reply:

Quote: references to the 13th floor tyaathome reply:

Come Help me ah. The problems are two days.

Specifically, I do not know, but personally feel that both sides of the serialized file package name to be the same

QQ know you do, I ask it plus you QQ. Ask too tangled. F5 constantly get answered.

The company can not ...
Reply:
cited 17 floor guoyoulei520 reply:
Quote: references to the 16th floor tyaathome reply:

Quote: 15th Floor guoyoulei520 cited reply:

Quote: references to the 13th floor tyaathome reply:

Come Help me ah. The problems are two days.

Specifically, I do not know, but personally feel that both sides of the serialized file package name to be the same

QQ know you do, I ask it plus you QQ. Ask too tangled. F5 constantly get answered.

The company can not ...

Is there any chat tool?
Reply:
reference to the 7th floor birdsaction reply:
jar command you to baidu search, is very simple.

You can help me solve. Thank you
Reply:




Right-click the eclipse project Export, find the jar
Then select the class you want to pack, make sure the dependencies between these classes.
Specify a path to OK
Reply:
cited 20 floor birdsaction reply:




Right-click the eclipse project Export, find the jar
Then select the class you want to pack, make sure the dependencies between these classes.
Specify a path to OK

Ah ha ha doing a good job. The original serialization and de-serialization of the package name to be consistent, so I wrote a project to fight the packages were placed in the two works, then the sequence of classes into re-use is no problem.


In java and android development
If the client (JAVA) and server (Android) using the Serializable interface,

You must ensure that the use Serializable interface class

The client and server projects class name and class where the package name consistent ~

Or be wrong ~ ~

I also Baidu to the top of this information before know.

No comments:

Post a Comment