Save Data To Sqlite From Json Object Using Hashmap In Android
Solution 1:
I'm not sure what you doing wrong, but I can help you with some debugging.
First where do you declare your table? Is this consistent with your data trying to insert?
In your for loop where you create your ContentValue and call insert, try to see what integer insert is returning, this is the row number or ID can't remember. But it's -1 if not inserted. If you get this the problem is probably some sort of type problem. Trying to save a string as a int or...?
Another great tool you could use is the sqlite3 command to inspect the database structure and the tables. The sqlite3 is not installed on an android device, so use the emulator for this, or read this on how to make it running on a device: How to install sqlite3
Solution 2:
this line is wrong
db.insert("Baranzan", DatabaseHelper.COUNTRY, cv);
try
db.insert(DatabaseHelper.COUNTRY, null, cv);
if you caught exception here
catch(JSONException e) {
Log.e("log_tag", "Error parsing data "+e.toString());
}
then you should provide log from logcat for more information
Solution 3:
edit this line
db.insert("Baranzan", DatabaseHelper.COUNTRY, cv);
to
db.insert ("mytable", null, cv);
Post a Comment for "Save Data To Sqlite From Json Object Using Hashmap In Android"