How to add new elements to an array?

后端 未结 18 1924
误落风尘
误落风尘 2020-11-22 04:55

I have the following code:

String[] where;
where.append(ContactsContract.Contacts.HAS_PHONE_NUMBER + \"=1\");
where.append(ContactsContract.Contacts.IN_VISIB         


        
18条回答
  •  天涯浪人
    2020-11-22 05:15

    As tangens said, the size of an array is fixed. But you have to instantiate it first, else it will be only a null reference.

    String[] where = new String[10];
    

    This array can contain only 10 elements. So you can append a value only 10 times. In your code you're accessing a null reference. That's why it doesnt work. In order to have a dynamically growing collection, use the ArrayList.

提交回复
热议问题