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 trialMUZ140028 Charlton Sibanda
5,615 Pointsanyone 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.
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"));
mrben
8,068 PointsWell 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.
MUZ140028 Charlton Sibanda
5,615 Pointsi still do not get it...the answer you gave didnt solve the problem mrben.....can you please show me the correct way
MUZ140028 Charlton Sibanda
5,615 Pointsthanks..it solved it now
2 Answers
mrben
8,068 PointsTry this:
database.update("PETS_TABLE", values, String.format("%s=%s", "name","Rover"), null);
mrben
8,068 PointsI 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?
MUZ140028 Charlton Sibanda
5,615 Pointsif 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
mrben
8,068 PointsThis 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.
MUZ140028 Charlton Sibanda
5,615 PointsMUZ140028 Charlton Sibanda
5,615 Pointsi clicked best answer by mistake there...would you please just show what you are saying