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 trialdlpuxdzztg
8,243 PointsDoes your object *need* parameters?
Evan Anger I'm applying what is taught in these videos into my own app, but when I got to this part:
ArrayList<ListItem> list = new ArrayList<ListItem>();
if (cursor.moveToFirst()) {
do {
ListItem listItem = new ListItem(getIntFromColumnName(cursor, BaseColumns._ID),
getStringFromColumnName(cursor, EasyListSQLiteHelper.LISTS_NAME),
getStringFromColumnName(cursor, EasyListSQLiteHelper.LISTS_CHECKED),
null);
list.add(listItem);
}while(cursor.moveToNext());
}
My 'ListItem' got an error as expected because it doesn't have any parameters. It only has two values: an int and string value (getters and setters for those too). So how would I go about reading my two values this way?
Also, do I need to put ListItem into the angle brackets after 'new'?
1 Answer
Chris Jones
Java Web Development Techdegree Graduate 23,933 PointsHey Diego, could you post your code for the ListItem class? That will help me understand the problem.
Thanks!
dlpuxdzztg
8,243 Pointsdlpuxdzztg
8,243 PointsChris Jones
Java Web Development Techdegree Graduate 23,933 PointsChris Jones
Java Web Development Techdegree Graduate 23,933 PointsIt looks like the problem is that your ListItem constructor doesn't have any parameters, but you're passing it some in your original code snippet.
It looks like you're trying to create a ListItem object for each record returned in a query. However, not all of the query results (_ID, LISTS_NAME, and LISTS_CHECKED) match the ListItem class fields (mListsList, mListName, and mImportant). LISTS_NAME is probably mListName and LISTS_CHECKED might be mImportant, but it doesn't look like you have a column in your query for mListsList.
Either way, if you're wanting to create a ListItem object from your query results, you're going to need to have a ListItem constructor like this:
Does that help some?
I don't know why some of the text in my answer is underlined - that's unintentional so please disregard it.
dlpuxdzztg
8,243 Pointsdlpuxdzztg
8,243 PointsThat's better, thank you!
Chris Jones
Java Web Development Techdegree Graduate 23,933 PointsChris Jones
Java Web Development Techdegree Graduate 23,933 PointsNot a problem! Please mark the answer as the Best Answer if it was helpful :)!