@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" +
KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
KEY_NAME + " TEXT NOT NULL, " +
KEY_SKILL + " TEXT NOT NULL" +
KEY_COUNTY + "TEXT NOT NULL);"
);
db.execSQL(" CREATE TABLE " + DATABASE_BANK + " ("+ //SQL CREATE statement for Bank table
KEY_ROWID + " INTEGER NOT NULL PRIMARY KEY);");
}
在on create方法中,我创建了这个表,但是当我运行应用程序时,它告诉我关键县有问题。下面我将发布logcat。它说"没有这样的专栏:business_county",我引用的唯一地方是这里
public static final String KEY_ROWID = "_id";
public static final String KEY_NAME = "persons_name";
public static final String KEY_SKILL = "persons_skill";
public static final String KEY_COUNTY = "business_county";
然而,我认为如果你把花生酱放在方括号中并不重要,那就是你想要的。
logcat的:
11-29 23:22:41.343 23491-23491/com.example.tl.firstdb W/InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed.
11-29 23:22:41.344 23491-23491/com.example.tl.firstdb W/ViewRootImpl: Dropping event due to root view being removed: MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=218.31485, y[0]=200.40204, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=185996190, downTime=185996177, deviceId=6, source=0x1002 }
11-29 23:22:41.344 23491-23491/com.example.tl.firstdb W/InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed.
11-29 23:22:42.101 23491-23491/com.example.tl.firstdb I/System.out: The Context from skillslevel class com.example.tl.firstdb.SQLView
11-29 23:22:42.105 23491-23491/com.example.tl.firstdb E/SQLiteLog: (1) no such column: business_county
11-29 23:22:42.106 23491-23491/com.example.tl.firstdb D/AndroidRuntime: Shutting down VM
11-29 23:22:42.107 23491-23491/com.example.tl.firstdb E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.tl.firstdb, PID: 23491
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.example.tl.firstdb/com.example.tl.firstdb.SQLView}: android.database.sqlite.SQLiteException: no such column: business_county (code 1): , while compiling: SELECT _id, persons_name, persons_skill, business_county FROM peopleTable
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2426)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
Caused by: android.database.sqlite.SQLiteException: no such column: business_county (code 1): , while compiling: SELECT _id, persons_name, persons_skill, business_county FROM peopleTable
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:887)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:498)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1316)
at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1163)
at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1034)
at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1202)
at com.example.tl.firstdb.SkillsLevel.getData(SkillsLevel.java:107)
at com.example.tl.firstdb.SQLView.onCreate(SQLView.java:37)
at android.app.Activity.performCreate(Activity.java:6245)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
答案 0 :(得分:1)
您在create table语句中缺少逗号,在Line
和TEXT NOT NULL
列名称之间。修复此错误后,您需要通过清除设置&gt;中的应用数据来删除数据库。应用程序,或卸载并重新安装。
答案 1 :(得分:0)
你在keykill之后错过了逗号,你需要在列名和列类型之间放置空格。就像这样..我在这里提到了&amp; nbsp .. KEY_COUNTY +“&amp; nbspTEXT NOT NULL);”< / p>