Android - null object reference when iterating List

前端 未结 1 519
北恋
北恋 2021-01-12 23:12

I\'m trying to copy a List \'usrs\' which is created in an Inner class to a different list \'team_memebers\'. After copying I try to iterate \'team_memebers\' in the FOR loo

相关标签:
1条回答
  • 2021-01-12 23:58

    Your problem is that you aren't iterating after copying list. query.findInBackground() is an async callback and therefore, isn't executed immediately. Because your iteration loop is PLACED below that callback, doesn't mean it will be executed after callback executes. Just put your loop inside callback like this:

    query.findInBackground(new FindCallback<ParseObject>() {
            public void done(List<ParseObject> usrs, ParseException e) {
                if (e == null) {
    
                team_memebers = new ArrayList<String>(usrs.size());
                for (ParseObject prso:usrs) {
                    team_memebers.add(new String(prso.getString("Username")));
                }
                for (String str:team_memebers)
                {
                    empolyeeSpinnerAdapter.add(str);
                }
            } else {//handle the error
            }
        }
    });
    
    0 讨论(0)
提交回复
热议问题