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 trialEden Gregory
3,850 PointsCRUD Operations with SQLite Stage 5 - Challenge 1
I am having trouble finding what is wrong with my code. Can anyone help? Thanks in advance.
Prompt: Hooray! We have a set of ContentValues! Insert them into the database. Assume you have a variable named database to call the insert() method from. Use "PETS_TABLE" as the table name. Reference the documentation if you need help with the parameters.
My code:
ContentValues values = new ContentValues(); values.put("name", "Rover"); values.put("type", "dog"); values.put("breed", "mixed");
/* Add your code here!
- Assume you already have a variable named 'database'. */ long valuesID = database.insert(PETS_TABLE, null, values);
ContentValues values = new ContentValues();
values.put("name", "Rover");
values.put("type", "dog");
values.put("breed", "mixed");
/* Add your code here!
* Assume you already have a variable named 'database'.
*/
1 Answer
CyCy William Parker
3,681 PointsHello Eden. Your problem here is that your first parameter needs to be a string your code reads
long valuesID = database.insert(PETS_TABLE, null, values);
when it should read
long valuesID = database.insert("PETS_TABLE", null, values);
Eden Gregory
3,850 PointsEden Gregory
3,850 PointsThank you.
Kien Doan
17,538 PointsKien Doan
17,538 PointsIt can too pass by typing
database.insert("PETS_TABLE", null, values);