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

anyone to help

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.

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" /* add param here */);

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

database.update(PETS_TABLE,values,String.format("%s=%s", "name","Rover"));

i clicked best answer by mistake there...would you please just show what you are saying

Well I think my answer did solve your original problem and now you have a new problem :-). I've commented below showing you how to fix the new problem.

i still do not get it...the answer you gave didnt solve the problem mrben.....can you please show me the correct way

thanks..it solved it now

2 Answers

Try this:

database.update("PETS_TABLE", values, String.format("%s=%s", "name","Rover"), null);

I think that you might need to put PETS_TABLE in quotes, i.e. "PETS_TABLE".

If that's not it, what error are you getting?

if i put it in quotes...i get the following JavaTester.java:44: error: method update in class SQLiteDatabase cannot be applied to given types;

database.update("PETS_TABLE",values,String.format("%s=%s", "name","Rover")); ^ required: String,ContentValues,String,String[]

found: String,ContentValues,String

reason: actual and formal argument lists differ in length 1 error

This is likely a different error to the one you were seeing before.

It means you're missing an argument in the call to database.update. You're passing 3 arguments and 4 are required. The last one is a string array. However, in this instance you probably just need to pass null.

Search for "public int update" on http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html.