作者:mobiledu2502909745 | 来源:互联网 | 2022-12-27 10:14
publicstaticfinalStringMYDATABASE_NAMEMY_DATABASE;publicstaticfinalStringMYDATABASE_
public static final String MYDATABASE_NAME = "MY_DATABASE";
public static final String MYDATABASE_TABLE = "MY_TABLE";
public static final String MYDATABASE_TABLE2 = "MY_TABLE2";
public static final int MYDATABASE_VERSION = 1;
public static final String KEY_ID = "_id";
public static final String KEY_ID2 = "_id2";
public static final String KEY_CONTENT1 = "Content1";
public static final String KEY_CONTENT2 = "Content2";
public static final String KEY_CONTENT3 = "Content3";
//create table MY_DATABASE (ID integer primary key, Content text not null);
private static final String SCRIPT_CREATE_DATABASE = "create table " + MYDATABASE_TABLE + " ("
+KEY_ID + " integer primary key autoincrement, "
+ KEY_CONTENT1 + " text not null);";
private static final String SCRIPT_CREATE_DATABASE2 = "create table " + MYDATABASE_TABLE2 + " ("
+ KEY_ID2 + " integer autoincrement, "
+ KEY_CONTENT2 + " text not null, "
+ KEY_CONTENT3 + " text not null, "
+ " FOREIGN KEY ("+KEY_ID2+") REFERENCES "+MYDATABASE_TABLE+" ("+KEY_ID+"));";
I can not find out what gives the following error, please help me out thank you.
我不知道是什么原因导致了以下的错误,请帮助我一下谢谢。
09-29 13:41:19.760: ERROR/Database(334): Failure 1 (near "autoincrement": syntax error) on 0x218df0 when preparing 'create table MY_TABLE2 (_id2 integer autoincrement, Content2 text not null, Content3 text not null, FOREIGN KEY (_id2) REFERENCES MY_TABLE (_id));'.
错误/数据库(334):在准备“创建表MY_TABLE2 (_id2整数自动递增,Content2文本不为空,Content3文本不为空,外键(_id2)引用MY_TABLE (_id))”时,0x218df0上的失败1(接近“自动递增”:语法错误);
09-29 13:41:19.770: DEBUG/AndroidRuntime(334): Shutting down VM
调试/ android系统(334):关闭VM
09-29 13:41:19.770: WARN/dalvikvm(334): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
警告/dalvikvm(334): threadid=1:带未捕获异常的线程退出(组=0x4001d800)
09-29 13:41:19.791: ERROR/AndroidRuntime(334): FATAL EXCEPTION: main
错误/安卓时间(334):致命异常:主要
09-29 13:41:19.791: ERROR/AndroidRuntime(334): java.lang.RuntimeException: Unable to start activity ComponentInfo{sep.com/sep.com.SepActivity}: android.database.sqlite.SQLiteException: near "autoincrement": syntax error: create table MY_TABLE2 (_id2 integer autoincrement, Content2 text not null, Content3 text not null, FOREIGN KEY (_id2) REFERENCES MY_TABLE (_id));
09-29 13:41:19.791:错误/ AndroidRuntime(334):. lang。RuntimeException:无法启动活动ComponentInfo {sep.com/sep.com.SepActivity }:android.database.sqlite。SQLiteException:临近“自动递增”:语法错误:创建表MY_TABLE2 (_id2整数自动递增,Content2文本不为空,Content3文本不为空,外键(_id2)引用MY_TABLE (_id);
5 个解决方案