0

this is what i am doing.

"e" is defined as

Option e[];

where Option is my class that implements Serializable

Intent intent =new Intent(this,list_create.class); 
intent.putExtra("element", e);
startActivity(intent); 

and in the second activity i am retrieving like this

Intent i = getIntent();
Option e = (Option)i.getSerializableExtra("element");

but its giving a java.io.notSerializableException at "startActivity(intent)". What am i doing wrong here??

nam_ph
  • 233
  • 1
  • 3
  • 12
  • May be you can find solution in this link [http://stackoverflow.com/questions/4551926/java-io-notserializableexception-while-writing-serializable-object-to-external-s][1] [1]: http://stackoverflow.com/questions/4551926/java-io-notserializableexception-while-writing-serializable-object-to-external-s – koti Aug 02 '12 at 05:19
  • i have seen both of them befor but none of them teaches how to send an array of objects. – nam_ph Aug 02 '12 at 05:29

5 Answers5

1

I am not confirm but, May be this can help,

intent.putParcelableArrayListExtra("elements", e);

from second activity get ,

Intent i = getIntent();
Option e = (Option)i.getParcelableArrayListExtra("element");
rajeshwaran
  • 1,512
  • 1
  • 18
  • 24
1

Use a ArrayList as container for Option. A Arraylist is Serializable. The List interface is not Serializable.

And even if Option is Serializable, the attributes of Option must be Serializable, too. If a attribute should not be transfered it must be flaged with the transient key word.

keiki
  • 3,260
  • 3
  • 30
  • 38
  • what do you mean by flagged with transient keyword? – nam_ph Aug 02 '12 at 08:57
  • its giving the same error when i am passing ArrayList of type Option. What should i do? – nam_ph Aug 02 '12 at 09:07
  • @User_ph flagged: like public static keyword transient is a additional java keyword to prevent serialization of a attribut. Probably one of your attributes is not Serializable. Maybe there are more information in the stacktrace. – keiki Aug 02 '12 at 09:12
  • oh got it. I should declare my ArrayList as: "Transient ArrayList – nam_ph Aug 02 '12 at 09:24
  • @User_ph No....you don't get it. You should first study what Serialization and transient means. Otherwise you wouldn't fully understand the answer. – keiki Aug 02 '12 at 10:44
0

i think you have to send array object as a bytes and then you have reconstruct from bytes

check this link

Java Serializable Object to Byte Array

Community
  • 1
  • 1
Vishwanath.M
  • 6,235
  • 11
  • 42
  • 56
0

Option is Serializable but you are sending and array of type Option which goes against the concept of serialization.

Instead, you should have in your Option class an array which contains all of the options you need to send. Then you put just that one element of type Option.

Benito Bertoli
  • 25,285
  • 12
  • 54
  • 61
0

You can pass whatever you want.

Make a new class, throw in it whatever you want, and make it implement Serializable.

public class myClass  implements Serializable{
// Whatever fields
}
Paschalis
  • 11,929
  • 9
  • 52
  • 82