mercredi 18 février 2015

android.database.sqlite.SQLiteException:table abc has no column named xyz

I am getting following error while trying to insert records in SQLLite database-



android.database.sqlite.SQLiteException: table jolly has no column named noOfShares (code 1): , while compiling: INSERT INTO jolly(noOfShares,id,noOfMustGos,noOfSeen,caption,noOfBeenTheres,location) VALUES (?,?,?,?,?,?,?)


I failed to understand why its showing column in this order-(noOfShares,id,noOfMustGos,noOfSeen,caption,noOfBeenTheres,location) while i created table with different order of columns and assigning value in same order..I tried uninstalling the app and also changing table name but it didn't resolved.


Adapter



VideoSql videoSql;
public View getView(final int i, View v, ViewGroup viewGroup) {
videoSql=new VideoSql();
DatabaseHandler db = new DatabaseHandler(mContext);
videoSql.setId(mVideos.get(i).getId());
videoSql.setCaption(mVideos.get(i).getCaption());
videoSql.setNoOfMustGos(mVideos.get(i).getNoOfMustGos());
videoSql.setNoOfShares(mVideos.get(i).getNoOfShares());
videoSql.setLocation(mVideos.get(i).getLocation());
videoSql.setNoOfBeenTheres(mVideos.get(i).getNoOfBeenTheres());
videoSql.setNoOfSeen(mVideos.get(i).getNoOfSeen());

db.addContact(videoSql);
}


DatabaseHandler



public class DatabaseHandler extends SQLiteOpenHelper {

// All Static variables
// Database Version
private static final int DATABASE_VERSION = 1;
VideoSql mvideo;
// Database Name
private static final String DATABASE_NAME = "TDatabase";

// Contacts table name
private static final String TABLE_JOLLY = "jolly";

// Contacts Table Columns names
private static final String KEY_ID = "id";
private static final String KEY_CAPTION = "caption";
private static final String KEY_LOCATION = "location";
private static final String KEY_NOSHARES = "noOfShares";
private static final String KEY_NOBEENTHERE = "noOfBeenTheres";
private static final String KEY_NOMUSTGO = "noOfMustGos";
private static final String KEY_NOCOMMENTS = "noOfComments";
private static final String KEY_NOSEEN = "noOfSeen";
private static final String KEY_USERNAME = "userName";
private static final String KEY_USERID = "userId";
private static final String KEY_TIMESTAMP ="timestamp" ;
private static final String KEY_FOLLOWED = "followed";
private static final String KEY_BEENTHERE = "beenThere";
private static final String KEY_MUSTGO = "mustGo";
private static final String KEY_NOFOLLOWED = "noOfFollowed";
private static final String KEY_NOFOLLOWERS = "noOfFollowers";
private static final String KEY_USERHANDLE = "userHandle";
private static final String KEY_DTS = "dts";
private static final String KEY_FEATURED = "featured";
public DatabaseHandler(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);

}
@Override
public void onCreate(SQLiteDatabase db) {


String CREATE_JOLLY_TABLE = "CREATE TABLE " + TABLE_JOLLY + "("
+ KEY_ID + KEY_CAPTION + KEY_LOCATION + KEY_NOSHARES + KEY_NOBEENTHERE +KEY_NOMUSTGO +
KEY_NOSEEN +")" ;
db.execSQL(CREATE_JOLLY_TABLE);
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

db.execSQL("DROP TABLE IF EXISTS " + TABLE_JOLLY);

onCreate(db);
}

public void addContact(VideoSql videoSql)
{
SQLiteDatabase db = this.getWritableDatabase();

ContentValues values = new ContentValues();
values.put(KEY_ID, videoSql.getId());
values.put(KEY_CAPTION, videoSql.getCaption());
values.put(KEY_LOCATION, videoSql.getLocation());
values.put(KEY_NOSHARES, videoSql.getNoOfShares());
values.put(KEY_NOBEENTHERE, videoSql.getNoOfBeenTheres());
values.put(KEY_NOMUSTGO, videoSql.getNoOfMustGos());

values.put(KEY_NOSEEN, videoSql.getNoOfSeen());

db.insert(TABLE_JOLLY, null, values);

Log.e("addcontact", videoSql.getCaption());
db.close(); // Closing database connection
}

// Getting All Contacts
public List<VideoSql> getAllContacts() {
List<VideoSql> contactList = new ArrayList<VideoSql>();

String selectQuery = "SELECT * FROM " + TABLE_JOLLY;

SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);


if (cursor.moveToFirst())
{
do
{
VideoSql videoinfo = new VideoSql();
videoinfo.setId(cursor.getString(0));
videoinfo.setCaption(cursor.getString(1));
videoinfo.setLocation(cursor.getString(2));
videoinfo.setNoOfShares(cursor.getString(3));
videoinfo.setNoOfBeenTheres(cursor.getString(4));
videoinfo.setNoOfMustGos(cursor.getString(5));

videoinfo.setNoOfSeen(cursor.getString(6));


contactList.add(videoinfo);
}
while (cursor.moveToNext());
}


return contactList;
}
}

Aucun commentaire:

Enregistrer un commentaire