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 trialoak agasi
2,240 PointsAndroid sqlite - Getting -1 as a result of insert to db
Hi all
I am trying to insert data to my database and getting -1 meaning there was some error and insertion failed. This is my code
public boolean insertData (String name, String phone, String address) { SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(NAME, name);
values.put(PHONE, phone);
values.put(ADDRESS, address);
long result = db.insert(TABLE_NAME, null, values);
if (result == -1)
return false;
else
return true;
}
What should I do next ?
Thanks