0

类定义

private class classSerial implements Serializable {
    private static final long serialVersionUID = 1L;
    String vString;
    boolean vBool;
    long vLong;
    int vInt;

    classSerial(){
     //initialize members;
    }
}

我仍然收到错误:

Caused by: java.io.NotSerializableException: com.example.....

当我writeObject尝试FileOutputStreamclassSerial.


根据我的阅读,我使用的数据类型, String, boolen,是. 所以,我不需要实现任何方法。longintSerializable

我在这里想念什么?


LOGCAT

09-16 19:58:26.170: W/dalvikvm(4278): threadid=1: thread exiting with uncaught exception (group=0x40018560)
09-16 19:58:26.201: E/AndroidRuntime(4278): FATAL EXCEPTION: main
09-16 19:58:26.201: E/AndroidRuntime(4278): java.lang.IllegalStateException: Could not execute method of the activity
09-16 19:58:26.201: E/AndroidRuntime(4278):     at android.view.View$1.onClick(View.java:2165)
09-16 19:58:26.201: E/AndroidRuntime(4278):     at android.view.View.performClick(View.java:2506)
09-16 19:58:26.201: E/AndroidRuntime(4278):     at android.view.View$PerformClick.run(View.java:9112)
09-16 19:58:26.201: E/AndroidRuntime(4278):     at android.os.Handler.handleCallback(Handler.java:587)
09-16 19:58:26.201: E/AndroidRuntime(4278):     at android.os.Handler.dispatchMessage(Handler.java:92)
09-16 19:58:26.201: E/AndroidRuntime(4278):     at android.os.Looper.loop(Looper.java:130)
09-16 19:58:26.201: E/AndroidRuntime(4278):     at android.app.ActivityThread.main(ActivityThread.java:3835)
09-16 19:58:26.201: E/AndroidRuntime(4278):     at java.lang.reflect.Method.invokeNative(Native Method)
09-16 19:58:26.201: E/AndroidRuntime(4278):     at java.lang.reflect.Method.invoke(Method.java:507)
09-16 19:58:26.201: E/AndroidRuntime(4278):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
09-16 19:58:26.201: E/AndroidRuntime(4278):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
09-16 19:58:26.201: E/AndroidRuntime(4278):     at dalvik.system.NativeStart.main(Native Method)
09-16 19:58:26.201: E/AndroidRuntime(4278): Caused by: java.lang.reflect.InvocationTargetException
09-16 19:58:26.201: E/AndroidRuntime(4278):     at java.lang.reflect.Method.invokeNative(Native Method)
09-16 19:58:26.201: E/AndroidRuntime(4278):     at java.lang.reflect.Method.invoke(Method.java:507)
09-16 19:58:26.201: E/AndroidRuntime(4278):     at android.view.View$1.onClick(View.java:2160)
09-16 19:58:26.201: E/AndroidRuntime(4278):     ... 11 more
09-16 19:58:26.201: E/AndroidRuntime(4278): Caused by: java.io.NotSerializableException: com.example.testing.serialActivity
09-16 19:58:26.201: E/AndroidRuntime(4278):     at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1535)
09-16 19:58:26.201: E/AndroidRuntime(4278):     at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1847)
09-16 19:58:26.201: E/AndroidRuntime(4278):     at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1689)
09-16 19:58:26.201: E/AndroidRuntime(4278):     at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1653)
09-16 19:58:26.201: E/AndroidRuntime(4278):     at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:1143)
09-16 19:58:26.201: E/AndroidRuntime(4278):     at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:413)
09-16 19:58:26.201: E/AndroidRuntime(4278):     at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1241)
09-16 19:58:26.201: E/AndroidRuntime(4278):     at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1575)
09-16 19:58:26.201: E/AndroidRuntime(4278):     at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1847)
09-16 19:58:26.201: E/AndroidRuntime(4278):     at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1689)
09-16 19:58:26.201: E/AndroidRuntime(4278):     at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1653)
09-16 19:58:26.201: E/AndroidRuntime(4278):     at com.example.testing.serialActivity.login(login_activity.java:277)
09-16 19:58:26.201: E/AndroidRuntime(4278):     at com.example.testing.serialtest.login(serialtest.java:34)
09-16 19:58:26.201: E/AndroidRuntime(4278):     ... 14 more
4

1 回答 1

3

问题很可能是你有一个内部类。即它不是静态的,因此它具有对不可序列化的外部类的引用。这就是检查存在的原因,以避免序列化您不打算的东西。

您会在堆栈跟踪中注意到它抱怨的类是另一个类。

NotSerializableException: com.example.testingserialActivity

尝试上课

private static class ClassSerial implement Serializable
于 2012-09-16T14:34:44.923 回答