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 trial

Android Android Data Persistence CRUD Operations with SQLite Updating Existing Data

I don't see the error of the code | updating existing data task 2

Once again, assume you have a variable named 'database'. Update the database using the 'values' and 'clause' variables and "PETS_TABLE" as the table name. Use the documentation for help on how to call the appropriate method to update this data.

I am not sure what is wrong.

CodeChallenge.java
ContentValues values = new ContentValues();
values.put("name", "Rover");
values.put("type", "cat");
values.put("breed", "grumpy");

String clause = String.format("%s=%s", "name", "Rover");

public void update(String table,
                   ContentValues values,
                   String whereClause,
                   String[] whereArgs) { database.update(SQLiteHelper.PETS_TABLE, updateAnnotations, 
                                                         String.format("%s=%d", BaseColumns._ID, annotation.getId()), null); }

1 Answer

Hi Jody,

First thing you don't need to put the logic inside a method. Secondly, the table name is "PETS_TABLE" and they did not state that SQLiteHelper.PETS_TABLE = "PETS_TABLE".

http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#update(java.lang.String, android.content.ContentValues, java.lang.String, java.lang.String[])

ContentValues values = new ContentValues();
values.put("name", "Rover");
values.put("type", "cat");
values.put("breed", "grumpy");

String clause = String.format("%s=%s", "name", "Rover");

/* Add your code here! 
 * Assume you already have a variable named 'database'.
 */

database.update("PETS_TABLE",values,clause,null);

if you don't feel confident about what you learned in the videos, I urge you to watch them again or read and understand the code.

Best of luck and happy coding ! :-) Adam