Java序列化由java.lang.IllegalArgumentException引起:不是原始字段

时间:2016-08-29 08:27:08

标签: java deserialization

我在异常追踪之下。任何人都可以建议。我在做ObjectInputStream.readObject()。它正在制造问题。

Exception: java.lang.RuntimeException: An error occured while executing doInBackground()
       at android.os.AsyncTask$3.done(AsyncTask.java:300)
       at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
       at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
       at java.util.concurrent.FutureTask.run(FutureTask.java:242)
       at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
       at java.lang.Thread.run(Thread.java:841)
Caused by java.lang.IllegalArgumentException: not a primitive field
       at java.lang.reflect.Field.setFField(Field.java)
       at java.lang.reflect.Field.setFloat(Field.java:746)
       at java.io.ObjectInputStream.readFieldValues(ObjectInputStream.java:1092)
       at java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:455)
       at java.io.ObjectInputStream.readObjectForClass(ObjectInputStream.java:1347)
       at java.io.ObjectInputStream.readHierarchy(ObjectInputStream.java:1244)
       at java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:1833)
       at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:762)
       at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1981)
       at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1938)

1 个答案:

答案 0 :(得分:0)

字段可以是基本类型或引用类型。有八种基本类型:boolean,byte,short,int,long,char,float和double。引用类型是java.lang.Object的直接或间接子类,包括接口,数组和枚举类型。

可能你的类包含一个不可序列化的引用类型字段, 尝试序列化类中的所有引用类型字段。