Android Parcel class error -


i have complete code copied android.preference.multiselectlistpreference. facing weird compilation errors following inner class:

line #1 original code , have added #line 2

for line #2

type mismatch: cannot convert void string[]

and uncommented line #1

multiple markers @ line - type mismatch: cannot convert void string[] - method readstringarray(string[]) in type parcel not applicable arguments ()

private static class savedstate extends basesavedstate {         set<string> values;          public savedstate(parcel source) {             super(source);             values = new hashset<string>();             //string[] strings = source.readstringarray(); //line #1             string[] strings = source.readstringarray(values.toarray(new string[0])); //line #2              final int stringcount = strings.length;             (int = 0; < stringcount; i++) {                 values.add(strings[i]);             }         }          public savedstate(parcelable superstate) {             super(superstate);         }          @override         public void writetoparcel(parcel dest, int flags) {             super.writetoparcel(dest, flags);             dest.writestringarray(values.toarray(new string[0]));         }          public static final parcelable.creator<savedstate> creator =                 new parcelable.creator<savedstate>() {             public savedstate createfromparcel(parcel in) {                 return new savedstate(in);             }              public savedstate[] newarray(int size) {                 return new savedstate[size];             }         };     } 

i amused these compilation errors ! writing own multi-select preference facing 1 , error stated above , have no idea of solving it.

appreciate help.

the method readstringarray() has no return value, why compiler complaining. need pass string array parameter , fills string array give it.

you call readstringarray() this:

string[] things = new string[5]; // array in parcel known have 5 elements source.readstringarray(things);

this works if know how big string array in parcel is. if array of fixed size can use this. if not, need write size of array parcel before write array, , reader of parcel can first read size of array, create suitably sized string array receive data.


Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -