1

I keep getting this Serializable error. Both of my classes implement it. I cant seem to find problem. I have gone through all classes and still cant find the cause. It only happens on older Android version, 2.3 and below. Seems to be working find on 4.0+?

Update

Right this problem is back for me.

This time i get

java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = ....datastructures.model.PortfolioAccount)

PorfolioAccount contrain all GSON object and variables.

and it caused by this

Caused by: java.io.NotSerializableException: android.os.Handler

I have checked all my classes that need to be Serializable, but still cant find nothing. Like before its only happening on old Android OS versions.

Nabdreas
  • 3,327
  • 4
  • 27
  • 30

3 Answers3

5

I believe that your object has an attribute that is not Serializable. Make sure that your class attributes are all implementing Serializable interface. If this in not the problem, I would recommend to implement Parcelable interface.

Corje
  • 158
  • 7
  • That was the problem, i had to go class by class in the end, and one of them didnt have serializable implemented. – Nabdreas Jan 17 '14 at 09:15
1

I was digging through the code and managed to find one class that didnt have it implemented! Problem is that i share this data between 2 classes and Logcat was throwing error about the class that had serializable implemented and not the other way around!

Nabdreas
  • 3,327
  • 4
  • 27
  • 30
0

Probabily you're using an exception handling or method call that are not supported by older versions of Android.

Let me make an example:

So some of new Android 4 capabilities are not implenented in Android 2.3 like ImageView.setLayerType. To avoid runtime error simply:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
   setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}

This approach should be used also with exceptions handling:

} catch (NetworkOnMainThreadException nomte) {
   // log this exception
} catch (SocketTimeoutException socketTimeoutException) {
   // log this exception
}

NetworkOnMainThreadException is not implemented in Android 2.3 so when the class is loaded (and not before!) the exception java.lang.VerifyError occurs during runtime.

Seraphim's
  • 12,559
  • 20
  • 88
  • 129