0

I am encountering the following issue:

Let's say I have a RiceContainerClass like so:

public class RiceContainerClass implements Serializable{
 private typeOfRice
 private countryOfOrigin

 ...

I am able extend this class, (maybe I want some SteamedRiceClass), but most importantly I am able to pass this class between Activities with my current implementation.

The issue arose when I decided that my Rice class might need to come with a Sauceable Interface.

I wrote the interface:

public interface Sauceable{

  public void setTypeOfSauce(Sauce sc)

  public Sauce getRiceSauce()
}

(In my program the Sauce is actually a Drawable)

When I modified my RiceContainerClass to implement the Sauce Interface:

public class RiceContainerClass implements Serializable, Sauceable

I get the following error during runtime from the logcat:

java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.example.app.RiceContainerClass)

Any advice on what to do? I tried making the Sauce class extend Serializable, thought maybe that would work to no avail.

aran
  • 10,978
  • 5
  • 39
  • 69
edc598
  • 317
  • 3
  • 11

1 Answers1

0

That means that app.RiceContainerClass is not Serializable.

Just make sure that this class implements the Serializable interface and define the methods to write and read the Object.

You can check some examples here.

edc598
  • 317
  • 3
  • 11
aran
  • 10,978
  • 5
  • 39
  • 69
  • Admittedly I guess I was being lazy not wanting to use Parcelable because of the extra code that has to be added to the implementing class. Thanks for the link to the example, I'll give it a try and let you know. What I find odd though is that I was implementing Serializable at first and then once I added the extra Sauecable interface it was telling me that it wasn't serializable. – edc598 Jun 19 '13 at 22:11
  • take a look here as well: http://www.developerphil.com/parcelable-vs-serializable/ – aran Jun 19 '13 at 22:12
  • 1
    Hey so I integrated your suggestion. Wasn't as bad as I thought it would be. However, in doing some further research I found out that Drawable isn't Serializable/Parcelable, so that's why I was getting the exception when I implemented my `Sauceable` class. There is a way to pass Drawable by casting it as a generic Object and the casting it back to a Drawable. 2 examples here:http://pastebin.com/NkUmpRm9 & http://stackoverflow.com/questions/4207120/need-to-pass-an-un-parcelable-object-between-activities. Thanks for your help! – edc598 Jun 21 '13 at 19:13
  • Thanks to you for sharing this info, I'm glad being helpful. Good luck! – aran Jun 22 '13 at 00:48