Skip to main content

database insertion working well on android emulator but not on device



I have created a database using this tutorial .





When I insert the values in my table, it works on the emulator and I have seen the values are inserted correctly. But when I run my application on a device, it gives me this error:







02-29 17:30:45.341: E/Database(3300):android.database.sqlite.SQLiteException:no such table: recently_used: , while compiling: INSERT INTO recently_used(iconsset_name, icon_name) VALUES(?, ?);

02-29 17:30:45.341: E/Database(3300): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)

02-29 17:30:45.341: E/Database(3300):at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:92)

02-29 17:30:45.341: E/Database(3300):at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:65)

02-29 17:30:45.341: E/Database(3300): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:83)

02-29 17:30:45.341: E/Database(3300): at android.database.sqlite.SQLiteStatement.<init> (SQLiteStatement.java:41)







Here is my database class.







public class DBHelpter extends SQLiteOpenHelper{



private static final String DATABASE_NAME = "DatabaseName.db";



public static final String ICONS_SET_TABLE_NAME = "iconset";

public static final String ID_ICONS_SET = "_id";

public static final String NAME_ICONS_SET ="name";

public static final String SERVER_ID_ICONS_SET = "serverid";

public static final String PRODUCT_ID_ICONSET = "productid";



public static final String ICON_TABLE_NAME = "icons";

public static final String ID_ICONS = "_id";



public static final String SERVER_ICON_ID = "serverid";

public static final String ICONSET_ID_ICONS = "iconsetid";



public static final String RECENTLY_USED_TABLE_NAME = "recently_used";

public static final String ICONS_NAME_RECENTLY = "icon_name";

public static final String ICONSSET_NAME_RECENTLY = "iconsset_name";

public static final String RECENTLY_ICONSET_ID = "_id";





public static final int DATABASE_VERSION_NO = 3;

public Context mContext = null;



public static final String mIconsSetQuery = "CREATE TABLE "+ICONS_SET_TABLE_NAME + "(" + ID_ICONS_SET +" INTEGER PRIMARY KEY AUTOINCREMENT," + NAME_ICONS_SET +" TEXT," + SERVER_ID_ICONS_SET +" INTEGER," + PRODUCT_ID_ICONSET +" TEXT);";

public static final String mIcons = "CREATE TABLE "+ ICON_TABLE_NAME + "(" + ID_ICONS+ " INTEGER PRIMARY KEY AUTOINCREMENT,"+ SERVER_ICON_ID + " INTEGER,"+ICONSET_ID_ICONS + " INTEGER);";

public static final String recently_table_query = "CREATE TABLE "+ RECENTLY_USED_TABLE_NAME + "(_id INTEGER PRIMARY KEY AUTOINCREMENT, icon_name TEXT,iconsset_name TEXT);";



public DBHelpter(Context context) {



super(context, DATABASE_NAME, null, DATABASE_VERSION_NO);

mContext = context;

}



@Override

public synchronized void close() {

super.close();

}



@Override

public synchronized SQLiteDatabase getReadableDatabase() {

return super.getReadableDatabase();

}



@Override

public synchronized SQLiteDatabase getWritableDatabase() {

return super.getWritableDatabase();

}



@Override

public void onCreate(SQLiteDatabase db) {



db.execSQL(mIconsSetQuery);

db.execSQL(mIcons);

db.execSQL(recently_table_query);



}



@Override

public void onOpen(SQLiteDatabase db) {

super.onOpen(db);

}



@Override

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

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

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

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



onCreate(db);

}

}







Here is the method i am using.







public void recentlyUsed(RecentlyUsedIcons recentlyUsedIcons) {



values.put(DBHelpter.ICONS_NAME_RECENTLY, recentlyUsedIcons.getIcon_name());

values.put(DBHelpter.ICONSSET_NAME_RECENTLY, recentlyUsedIcons.getIconSet_name());

mDatabase.insert(DBHelpter.RECENTLY_USED_TABLE_NAME, null, values);







}


Comments

Popular posts from this blog

Why is this Javascript much *slower* than its jQuery equivalent?

I have a HTML list of about 500 items and a "filter" box above it. I started by using jQuery to filter the list when I typed a letter (timing code added later): $('#filter').keyup( function() { var jqStart = (new Date).getTime(); var search = $(this).val().toLowerCase(); var $list = $('ul.ablist > li'); $list.each( function() { if ( $(this).text().toLowerCase().indexOf(search) === -1 ) $(this).hide(); else $(this).show(); } ); console.log('Time: ' + ((new Date).getTime() - jqStart)); } ); However, there was a couple of seconds delay after typing each letter (particularly the first letter). So I thought it may be slightly quicker if I used plain Javascript (I read recently that jQuery's each function is particularly slow). Here's my JS equivalent: document.getElementById('filter').addEventListener( 'keyup', function () { var jsStart = (new Date).getTime()...

Is it possible to have IF statement in an Echo statement in PHP

Thanks in advance. I did look at the other questions/answers that were similar and didn't find exactly what I was looking for. I'm trying to do this, am I on the right path? echo " <div id='tabs-".$match."'> <textarea id='".$match."' name='".$match."'>". if ($COLUMN_NAME === $match) { echo $FIELD_WITH_COLUMN_NAME; } else { } ."</textarea> <script type='text/javascript'> CKEDITOR.replace( '".$match."' ); </script> </div>"; I am getting the following error message in the browser: Parse error: syntax error, unexpected T_IF Please let me know if this is the right way to go about nesting an IF statement inside an echo. Thank you.