android.database.sqlite.SQLiteException: near "autoincrement": syntax error (code 1): , while com

                                   菜鸟错误大全(三)

我们都是从新手一步一个坑踩过来的,下面我们来讲讲会遇到的常见错误和解决办法:
android.database.sqlite.SQLiteException: near “autoincrement”: syntax error (code 1): , while compiling: create table Book(id integer primarry key autoincrement,author text,price real,pages integer,name text):SQL语句创建数据库的时候,语句写错,看关键字有没有写错,例如CREATE_BOOK=”create table Book(“+”id integer primarry key autoincrement,”+”author text,”+”price real,”+”pages integer,”+”name text)”;中的primarry写错了,就会报错,应该改为primary

发布了50 篇原创文章 · 获赞 7 · 访问量 6万+
展开阅读全文

androidsqlite一直报错

01-14

在应用中用到sqlite,创建了一些表,代码如下: db.execSQL("CREATE TABLE IF NOT EXISTS " + GAMES_HISTORY_TABLE+ " (" + GAME_KEY + " INTEGER PRIMARY KEY AUTOINCREMENT, " + RIGHT_DRILLS + "INTEGER NOT NULL, " + NUM_OF_DRILLS + "INTEGER NOT NULL, " + GAME_DATE + "DATE);" ); 添加记录的代码: public long addScore(int totalDrills, int numberOfRightDrills) { ContentValues cv = new ContentValues(); cv.put(RIGHT_DRILLS, numberOfRightDrills); cv.put(NUM_OF_DRILLS, totalDrills); Date date = new Date(); SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); cv.put(GAME_DATE, dateFormat.format(date)); return dataBase.insert(GAMES_HISTORY_TABLE, null, cv); } 常变量的声明如下: private static final String GAMES_HISTORY_TABLE = "scoers"; private static final String GAME_KEY = "game_id"; private static final String RIGHT_DRILLS = "number_of_rihgt_drill"; private static final String NUM_OF_DRILLS = "total_drill"; private static final String GAME_DATE = "game_date"; 然后在logcat中获得下面异常: 01-13 20:13:45.485: D/szipinf(658): Initializing inflate state 01-13 20:13:47.375: D/szipinf(658): Initializing inflate state 01-13 20:13:47.485: I/Database(658): sqlite returned: error code = 1, msg = table scoers has no column named game_date 01-13 20:13:47.495: E/Database(658): Error inserting game_date=13-01-2013 20:13:47 total_drill=4 number_of_rihgt_drill=0 01-13 20:13:47.495: E/Database(658): android.database.sqlite.SQLiteException: table scoers has no column named game_date: , while compiling: INSERT INTO scoers(game_date, total_drill, number_of_rihgt_drill) VALUES(?, ?, ?); 01-13 20:13:47.495: E/Database(658): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method) 01-13 20:13:47.495: E/Database(658): at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:92) 01-13 20:13:47.495: E/Database(658): at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:65) 01-13 20:13:47.495: E/Database(658): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:83) 01-13 20:13:47.495: E/Database(658): at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:41) 01-13 20:13:47.495: E/Database(658): at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:1149) 01-13 20:13:47.495: E/Database(658): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1569) 01-13 20:13:47.495: E/Database(658): at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1426) 01-13 20:13:47.495: E/Database(658): at com.simplemathgame.GameDB.addScore(GameDB.java:83) 01-13 20:13:47.495: E/Database(658): at com.simplemathgame.Results.onCreate(Results.java:99) 01-13 20:13:47.495: E/Database(658): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 01-13 20:13:47.495: E/Database(658): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) 01-13 20:13:47.495: E/Database(658): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) 01-13 20:13:47.495: E/Database(658): at android.app.ActivityThread.access$1500(ActivityThread.java:117) 01-13 20:13:47.495: E/Database(658): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) 01-13 20:13:47.495: E/Database(658): at android.os.Handler.dispatchMessage(Handler.java:99) 01-13 20:13:47.495: E/Database(658): at android.os.Looper.loop(Looper.java:123) 01-13 20:13:47.495: E/Database(658): at android.app.ActivityThread.main(ActivityThread.java:3683) 01-13 20:13:47.495: E/Database(658): at java.lang.reflect.Method.invokeNative(Native Method) 01-13 20:13:47.495: E/Database(658): at java.lang.reflect.Method.invoke(Method.java:507) 01-13 20:13:47.495: E/Database(658): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 01-13 20:13:47.495: E/Database(658): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 01-13 20:13:47.495: E/Database(658): at dalvik.system.NativeStart.main(Native Method) 01-13 20:13:47.495: I/Database(658): sqlite returned: error code = 1, msg = no such column: sent 01-13 20:13:47.495: W/System.err(658): android.database.sqlite.SQLiteException: no such column: sent: , while compiling: SELECT sent FROM feedback 01-13 20:13:47.495: W/System.err(658): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method) 01-13 20:13:47.506: W/System.err(658): at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:92) 01-13 20:13:47.506: W/System.err(658): at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:65) 01-13 20:13:47.506: W/System.err(658): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:83) 01-13 20:13:47.506: W/System.err(658): at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:49) 01-13 20:13:47.506: W/System.err(658): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:42) 01-13 20:13:47.506: W/System.err(658): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1356) 01-13 20:13:47.506: W/System.err(658): at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1235) 01-13 20:13:47.506: W/System.err(658): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1189) 01-13 20:13:47.506: W/System.err(658): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1271) 01-13 20:13:47.506: W/System.err(658): at com.simplemathgame.GameDB.isFeedbackGiven(GameDB.java:117) 01-13 20:13:47.506: W/System.err(658): at com.simplemathgame.Results.onCreate(Results.java:100) 01-13 20:13:47.506: W/System.err(658): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 01-13 20:13:47.506: W/System.err(658): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) 01-13 20:13:47.506: W/System.err(658): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) 01-13 20:13:47.506: W/System.err(658): at android.app.ActivityThread.access$1500(ActivityThread.java:117) 01-13 20:13:47.515: W/System.err(658): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) 01-13 20:13:47.515: W/System.err(658): at android.os.Handler.dispatchMessage(Handler.java:99) 01-13 20:13:47.515: W/System.err(658): at android.os.Looper.loop(Looper.java:123) 01-13 20:13:47.515: W/System.err(658): at android.app.ActivityThread.main(ActivityThread.java:3683) 01-13 20:13:47.515: W/System.err(658): at java.lang.reflect.Method.invokeNative(Native Method) 01-13 20:13:47.515: W/System.err(658): at java.lang.reflect.Method.invoke(Method.java:507) 01-13 20:13:47.515: W/System.err(658): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 01-13 20:13:47.515: W/System.err(658): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 01-13 20:13:47.515: W/System.err(658): at dalvik.system.NativeStart.main(Native Method) 01-13 20:13:47.525: W/db(658): problem 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览