我想寫的Android手機上的客戶端和發送對象到服務器我的Windows PC上運行(使用ObjectDecoderInputStream),但這些異常Netty的ObjectEncoders/ObjectDecoders造成StreamCorruptedException
異常
java.io.StreamCorruptedException: unexpected end of block data
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.access$300(Unknown Source)
at java.io.ObjectInputStream$GetFieldImpl.readFields(Unknown Source)
at java.io.ObjectInputStream.readFields(Unknown Source)
at java.net.InetSocketAddress.readObject(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at java.io.ObjectStreamClass.invokeReadObject(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at org.jboss.netty.handler.codec.serialization.ObjectDecoderInputStream.readObject(ObjectDecoderInputStream.java:115)
at MainActivity.main(MainActivity.java:30)
但是,當我在我的電腦上使用CompatibleObjectEncoder/Decoder和我的PC上的ObjectInputStream時,它工作正常。如果我將android代碼更改爲Java代碼,並在我的PC上運行客戶端以使用ObjectEncoder及其相關的InputStream將自己的對象發送給對象,那麼它工作正常。
順便說一句,我使用netty 3.6.3最終和我的android設備是2.3.7薑餅(它使用jre 1.5或1.6),我的電腦是1.7,這可能是一個問題?
Netty的IO開始使用Java 7班自3.5.0,嘗試netty降級到3.4.x,看看是否有效。 – yorkw 2013-03-14 20:44:16
我試過3.4.6,3.4.2,3.2.6,但都沒有工作。我認爲它是因爲android有它自己的環境,它不兼容Java 6和7. – user2049241 2013-03-16 02:50:20