I am making a simple twitter like app where a user can follow or post.

I am using parse android for this.

In the users table I have created a column called "isFollowing" which indicates name of followers.

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                CheckedTextView checkedTextView=(CheckedTextView)view;
                if (checkedTextView.isChecked()){
                    ParseUser.getCurrentUser().getList("isFollowing").add(users.get(position));
                }else {
                    ParseUser.getCurrentUser().getList("isFollowing").remove(users.get(position));
                }
                ParseUser.getCurrentUser().saveInBackground();
            }
        });

The users arrayList contains the number of users present. If we click on list view then the name of the user will be added into isFollowing array in the parse database.

I am using ParseUser.getCurrentUser().getList("isFollowing").add(users.get(position)); to add the username to my array which is giving me a null pointer exception.

But if I use ParseUser.getCurrentUser.add("isFollowing", users.get(position)), then it is getting executed correctly.

Why is this happening?

1

There are 1 answers

3
Davi Macêdo On BEST ANSWER

Probably in the first moment your list is not initialize, so getList("isFollowing") return null. Are you setting an empty [] array when creating this user to this field?

Also, if you expect this array to grow over time and in some cases hit > 20 items, you can have performance problems in the future. I'd use relation or pointer fields to store this kind of data.