Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List<String> readStringArray in Parcelable

Most of my Parcelable is working; Simple things like out.writeString, out.writeInt, in.readString() etc are working perfectly.

My problem is when I want to Parcel an Array / List / ArrayList (I've tried them all).

I'm currently trying with:

List<String>

and

out.writeStringList()

works fine.

Eclipse suggests that there is a

in.readStringList(List<String> list)

to read that data back in. But it's not doing it for me.

What are we supposed to put into the ()?

I've tried nothing, with the result 'Add argument to match...' I've tried null, reference to the getter amongst others; which all return the error 'cannot convert from void to List'

like image 505
DaveSav Avatar asked Feb 23 '12 02:02

DaveSav


1 Answers

'cannot convert from void to List'

From that error it sounds like you're trying to assign the return type of the method readStringList(...) to a List<T> variable. In other words: are you perhaps writing something like:

List<String> stringList = in.readStringList(stringList)

? readStringList(...) returns a void, so that might be what Eclipse is complaining about. You actually should not be trying to a get a return type from a void method - in this case you need to supply the variable to which the result should be assigned as a parameter. Hence, this should suffice:

List<String> stringList = null;
in.readStringList(stringList)

By the way, if you're implementing Parcelable in order to be able to pass relatively simple data objects between activities (using Intents), consider using the Serializable interface in stead - it'll save you tons of work, especially if you need to repeat the same process for multiple objects.

like image 147
MH. Avatar answered Sep 18 '22 19:09

MH.