本文介绍了SQLiteException:临近"在数据库中插入null时与QUOT;:语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
好日子,只是为了简短有关code,
Good day, Just to make it short with relevant code,
如果我这样做在我的活动:
If i do this in my activity:
Intent i = getIntent();
Bundle extras = i.getExtras();
BitmapFactory.Options bf = new BitmapFactory.Options();
bf.inSampleSize = 2;
filename = extras.getString("pic_name");
ImageView iv = new ImageView(getApplicationContext());
Bitmap bm = BitmapFactory.decodeFile(filename, bf);
iv.setImageBitmap(bm);
setContentView(iv);
registerForContextMenu(iv);
public boolean onContextItemSelected(MenuItem item){
// weatherimagedb = new WeatherImageDB(this);
//weatherimagedb.open();
ContentValues vals = new ContentValues();
int selection = item.getItemId();
switch(selection){
case Holidays:
vals.put(ImageDB.HOLIDAYS, filename);
break;
case Weather:
vals.put(ImageDB.WEATHER, filename);
break;
}
imagedb.tagImage(filename, vals); //logcat error is here
return true;
}
和中下,imageDB数据库类我有这样一个方法:
And in the imageDB database class i have a method like this:
public long tagImage(String pathname, ContentValues val){
return db.insert(DATABASE_TABLE, null, val); //logcat error is here
}
我得到这个数据库的错误,但它不会崩溃我的应用程序:
i get this error in database, but it does not crash my app:
05-19 02:44:55.580: E/Database(3088): Error inserting
05-19 02:44:55.580: E/Database(3088): android.database.sqlite.SQLiteException: near "null": syntax error: , while compiling: INSERT INTO imagetags(null) VALUES(NULL);
05-19 02:44:55.580: E/Database(3088): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
05-19 02:44:55.580: E/Database(3088): at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:92)
05-19 02:44:55.580: E/Database(3088): at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:65)
05-19 02:44:55.580: E/Database(3088): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:83)
05-19 02:44:55.580: E/Database(3088): at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:41)
05-19 02:44:55.580: E/Database(3088): at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:1231)
05-19 02:44:55.580: E/Database(3088): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1658)
05-19 02:44:55.580: E/Database(3088): at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1515)
05-19 02:44:55.580: E/Database(3088): at com.MyApps.ImageUpdate.ImageDB.tagImage(ImageDB.java:82)
05-19 02:44:55.580: E/Database(3088): at com.MyApps.ImageUpdate.ViewImage.onContextItemSelected(ViewImage.java:134)
05-19 02:44:55.580: E/Database(3088): at android.app.Activity.onMenuItemSelected(Activity.java:2254)
什么可能我是做错了吗?..我不能使用ContentValues正确就够了吗?
what could i be doing wrong please?.. am i not using the ContentValues correctly enough?
感谢您。
推荐答案
难道说你的选
既不是假期
也不天气
?
Could it be that your selection
is neither Holidays
nor Weather
?
这篇关于SQLiteException:临近&QUOT;在数据库中插入null时与QUOT;:语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!