-2

I got this code

public void displayText(){
    int resourceId = getResources().getIdentifier(chosenArrayName, "array", getPackageName());
    String[] array = getResources().getStringArray(resourceId);
    int arraySize = array.size();
    for(int i = 0; i < arraySize; i++) {
        textView.append(array[i]);}

    }

From Android how to print a array in text view or anything

The arraySize = array.size(); cannot be resolved. Anyone help me to point out why?

Anthony
  • 51
  • 7

1 Answers1

0

You cannot call size() method in int. Try this :

public void displayText(){
    int resourceId = getResources().getIdentifier(chosenArrayName, "array", getPackageName());
    String[] array = getResources().getStringArray(resourceId);
    int arraySize = array.length;
    for(int i = 0; i < arraySize; i++) {
        textView.append(array[i]);}
}
Thomas Mary
  • 1,535
  • 1
  • 13
  • 24
  • Just change the size() to length. will solve the problem, Thanks I don't know why they downvote too. But thanks for your answer – Anthony Dec 18 '17 at 09:05