我正在尝试向我的数据库添加一些内容,但我一直收到错误消息,指出列不存在.我查看了使用的表格root explorer
,它只创建了前两列的id
和name
.这就是我最初在那里所有的,但后来我添加了几个列,现在它甚至在我完成程序的全新安装后也给了我错误.
它是一个内容提供商,如果重要的话
12-08 16:55:21.470: E/SQLiteDatabase(23282): Error inserting series=0 team_pos=0 handed=0 name=Allen, Andrew substitute=0 game=0 team=0 average=0 12-08 16:55:21.470: E/SQLiteDatabase(23282): android.database.sqlite.SQLiteException: table bowlers_table has no column named series: , while compiling: INSERT INTO bowlers_table(series,team_pos,handed,name,substitute,game,team,average) VALUES (?,?,?,?,?,?,?,?) 12-08 16:55:21.470: E/SQLiteDatabase(23282): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method) 12-08 16:55:21.470: E/SQLiteDatabase(23282): at android.database.sqlite.SQLiteCompiledSql.(SQLiteCompiledSql.java:64) 12-08 16:55:21.470: E/SQLiteDatabase(23282): at android.database.sqlite.SQLiteProgram.compileSql(SQLiteProgram.java:146) 12-08 16:55:21.470: E/SQLiteDatabase(23282): at android.database.sqlite.SQLiteProgram.compileAndbindAllArgs(SQLiteProgram.java:367) 12-08 16:55:21.470: E/SQLiteDatabase(23282): at android.database.sqlite.SQLiteStatement.acquireAndLock(SQLiteStatement.java:253) 12-08 16:55:21.470: E/SQLiteDatabase(23282): at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:111) 12-08 16:55:21.470: E/SQLiteDatabase(23282): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1737) 12-08 16:55:21.470: E/SQLiteDatabase(23282): at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1610) 12-08 16:55:21.470: E/SQLiteDatabase(23282): at com.tyczj.bowling.BowlersDB.insert(BowlersDB.java:102) 12-08 16:55:21.470: E/SQLiteDatabase(23282): at android.content.ContentProvider$Transport.insert(ContentProvider.java:203) 12-08 16:55:21.470: E/SQLiteDatabase(23282): at android.content.ContentResolver.insert(ContentResolver.java:721) 12-08 16:55:21.470: E/SQLiteDatabase(23282): at com.tyczj.bowling.Bowlers.onDoneClick(Bowlers.java:58) 12-08 16:55:21.470: E/SQLiteDatabase(23282): at java.lang.reflect.Method.invokeNative(Native Method) 12-08 16:55:21.470: E/SQLiteDatabase(23282): at java.lang.reflect.Method.invoke(Method.java:491) 12-08 16:55:21.470: E/SQLiteDatabase(23282): at android.view.View$1.onClick(View.java:2690) 12-08 16:55:21.470: E/SQLiteDatabase(23282): at android.view.View.performClick(View.java:3122) 12-08 16:55:21.470: E/SQLiteDatabase(23282): at android.view.View$PerformClick.run(View.java:12020) 12-08 16:55:21.470: E/SQLiteDatabase(23282): at android.os.Handler.handleCallback(Handler.java:587) 12-08 16:55:21.470: E/SQLiteDatabase(23282): at android.os.Handler.dispatchMessage(Handler.java:92) 12-08 16:55:21.470: E/SQLiteDatabase(23282): at android.os.Looper.loop(Looper.java:132) 12-08 16:55:21.470: E/SQLiteDatabase(23282): at android.app.ActivityThread.main(ActivityThread.java:4126) 12-08 16:55:21.470: E/SQLiteDatabase(23282): at java.lang.reflect.Method.invokeNative(Native Method) 12-08 16:55:21.470: E/SQLiteDatabase(23282): at java.lang.reflect.Method.invoke(Method.java:491) 12-08 16:55:21.470: E/SQLiteDatabase(23282): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844) 12-08 16:55:21.470: E/SQLiteDatabase(23282): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602) 12-08 16:55:21.470: E/SQLiteDatabase(23282): at dalvik.system.NativeStart.main(Native Method) 12-08 16:55:21.470: E/AndroidRuntime(23282): FATAL EXCEPTION: main 12-08 16:55:21.470: E/AndroidRuntime(23282): java.lang.IllegalStateException: Could not execute method of the activity 12-08 16:55:21.470: E/AndroidRuntime(23282): at android.view.View$1.onClick(View.java:2695) 12-08 16:55:21.470: E/AndroidRuntime(23282): at android.view.View.performClick(View.java:3122) 12-08 16:55:21.470: E/AndroidRuntime(23282): at android.view.View$PerformClick.run(View.java:12020) 12-08 16:55:21.470: E/AndroidRuntime(23282): at android.os.Handler.handleCallback(Handler.java:587) 12-08 16:55:21.470: E/AndroidRuntime(23282): at android.os.Handler.dispatchMessage(Handler.java:92) 12-08 16:55:21.470: E/AndroidRuntime(23282): at android.os.Looper.loop(Looper.java:132) 12-08 16:55:21.470: E/AndroidRuntime(23282): at android.app.ActivityThread.main(ActivityThread.java:4126) 12-08 16:55:21.470: E/AndroidRuntime(23282): at java.lang.reflect.Method.invokeNative(Native Method) 12-08 16:55:21.470: E/AndroidRuntime(23282): at java.lang.reflect.Method.invoke(Method.java:491) 12-08 16:55:21.470: E/AndroidRuntime(23282): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844) 12-08 16:55:21.470: E/AndroidRuntime(23282): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602) 12-08 16:55:21.470: E/AndroidRuntime(23282): at dalvik.system.NativeStart.main(Native Method) 12-08 16:55:21.470: E/AndroidRuntime(23282): Caused by: java.lang.reflect.InvocationTargetException 12-08 16:55:21.470: E/AndroidRuntime(23282): at java.lang.reflect.Method.invokeNative(Native Method) 12-08 16:55:21.470: E/AndroidRuntime(23282): at java.lang.reflect.Method.invoke(Method.java:491) 12-08 16:55:21.470: E/AndroidRuntime(23282): at android.view.View$1.onClick(View.java:2690) 12-08 16:55:21.470: E/AndroidRuntime(23282): ... 11 more 12-08 16:55:21.470: E/AndroidRuntime(23282): Caused by: android.database.SQLException: Failed to insert row into content://com.tyczj.bowling.bowlersdb/bowlers_table 12-08 16:55:21.470: E/AndroidRuntime(23282): at com.tyczj.bowling.BowlersDB.insert(BowlersDB.java:108) 12-08 16:55:21.470: E/AndroidRuntime(23282): at android.content.ContentProvider$Transport.insert(ContentProvider.java:203) 12-08 16:55:21.470: E/AndroidRuntime(23282): at android.content.ContentResolver.insert(ContentResolver.java:721) 12-08 16:55:21.470: E/AndroidRuntime(23282): at com.tyczj.bowling.Bowlers.onDoneClick(Bowlers.java:58) 12-08 16:55:21.470: E/AndroidRuntime(23282): ... 14 more
这是我插入的时候
public void onDoneClick(View v){ EditText et = (EditText)findViewById(R.id.editText1); ContentValues contentValues = new ContentValues(); contentValues.put(BowlersDB.NAME,et.getText().toString()); contentValues.put(BowlersDB.HANDED,"0"); contentValues.put(BowlersDB.TEAM,"0"); contentValues.put(BowlersDB.SUB,"0"); contentValues.put(BowlersDB.POSITION,"0"); contentValues.put(BowlersDB.AVERAGE,"0"); contentValues.put(BowlersDB.GAME,"0"); contentValues.put(BowlersDB.SERIES,"0"); et.setText(""); getContentResolver().insert(BowlersDB.CONTENT_URI, contentValues); }
和我的数据库插入
@Override public Uri insert(Uri uri, ContentValues values) { long rowID = db.insert(BOWLERS_TABLE,null, values); if(rowID > 0){ Uri _uri = ContentUris.withAppendedId(CONTENT_ID_URI_BASE,rowID); getContext().getContentResolver().notifyChange(_uri,null); return _uri; }else{ throw new SQLException("Failed to insert row into " + uri); } }
以及我如何在内容提供商中创建表格
private void createTables(SQLiteDatabase db){ db.execSQL("CREATE TABLE " + BOWLERS_TABLE + "(" + ID + " integer primary key autoincrement, " + NAME + " TEXT " + TEAM + " TEXT " + SUB + " TEXT " + POSITION + " TEXT " + AVERAGE + " TEXT " + GAME + " TEXT " + SERIES + " TEXT " + HANDED + " TEXT);"); }
在这种方式之前我做了很多表,所以我不知道为什么这不是创造
您在创建数据库表的SQL代码中忘记了"TEXT"之后的逗号.