Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialEilon Krauthammer
4,768 PointsListView doesn't display anything
Hi, I'm following the video and when I try to run the project, nothing shows up in my ListView... Here's my onResume method:
@Override
protected void onResume() {
super.onResume();
ParseQuery<ParseUser> query = ParseQuery.getQuery("User");
query.orderByAscending(ParseConstants.KEY_USERNAME);
query.setLimit(1000);
query.findInBackground(new FindCallback<ParseUser>() {
@Override
public void done(List<ParseUser> parseUsers, ParseException e) {
if (e == null) {
mUsers = parseUsers;
String[] usernames = new String[mUsers.size()];
int i = 0;
for (ParseUser user : mUsers) {
usernames[i] = user.getUsername();
Log.v(TAG, user.getUsername());
i++;
}
for (int j = 0; j < usernames.length; i++) {
Log.v(TAG, usernames[j]);
}
ArrayAdapter<String> adapter =
new ArrayAdapter<String>
(EditFriendsActivity.this, android.R.layout.simple_list_item_1, usernames);
setListAdapter(adapter);
} else {
Toast.makeText
(EditFriendsActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
}
}
});
}
As you can see I also try to log the users but nothing happens, and I get the following warning:
Before Android 4.1, method int android.support.v7.internal.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
But I don't find it particularly helpful... Why doesn't it work? Thanks!
1 Answer
Ben Jakuben
Treehouse TeacherThat error message is just a warning that I think you can ignore. Not totally sure, though.
Have you tried debugging your code? Add a few breakpoints and see how it executes and what data is returned, if any. Have you double-checked the name ("User") of the Parse class you are querying?
Eilon Krauthammer
4,768 PointsEilon Krauthammer
4,768 PointsApparently I just had to change back to the ParseUser.getQuery, but it shows me that it's deprecated... any reasons why/better solution?
Karan Khare
3,477 PointsKaran Khare
3,477 PointsHi Ben, I need your help on this, would really appreciate if you can help me through. I have organized my import. So when i am extending my app to ListActivity then my app is crashing. and so i just extend my class to Activity and commented the setListAdapter line and i tried debugging the value i am getting from parse.com is "[Ljava.lang.String;@1565baf3". So few things:- 1) is their any alternate for setListAdapter and how should solve this problem 2) is this the way we get value from parse.com or there is some issue with this. public class EditFriendActivity extends ListActivity {
@Override protected void onResume() { super.onResume(); setProgressBarIndeterminateVisibility(true); ParseQuery<ParseUser> query = ParseUser.getQuery(); query.orderByAscending("username"); query.setLimit(500); query.findInBackground(new FindCallback<ParseUser>() { @Override public void done(List<ParseUser> users, ParseException e) { setProgressBarIndeterminateVisibility(false); if(e==null){ mUsers = users; String usernames[] = new String[mUsers.size()]; int count=0; for(ParseUser user: mUsers){ usernames[count]=user.getUsername(); count++; } Log.v("TAG",usernames + ""); ArrayAdapter<String> adapter = new ArrayAdapter<>(EditFriendActivity.this, android.R.layout.simple_list_item_checked,usernames);
Would really appreciate your help