我在创建SQL表时遇到了一些错误,报告java.lang.RuntimeException: An error occured while executing doInBackground()
Caused by: android.database.sqlite.SQLiteException: near "group": syntax error (code 1):
并试图解决整个下午而没有任何成功......有人会提供一些帮助吗?非常感谢提前!
private class Get_Ex_Data_Task extends AsyncTask<Object, Object, Cursor>
{
DatabaseConnector databaseConnector = new DatabaseConnector(Exercises_Main.this);
@Override
protected Cursor doInBackground(Object... params)
{
databaseConnector.open(); //LINE 65
return databaseConnector.get_All_Ex_Data();
}
public Cursor get_All_Ex_Data()
{
return database.query("DB_ex", new String[] {"_id", "name"}, null, null, null, null, "name");
}
private class DatabaseOpenHelper extends SQLiteOpenHelper
{
public DatabaseOpenHelper(Context context, String name, CursorFactory factory, int version)
{
super(context, name, factory, version);
}
@Override
public void onCreate(SQLiteDatabase db)
{
String createQuery = "CREATE TABLE exercises" +
"(_id integer primary key autoincrement," +
"name TEXT, group TEXT, calory TEXT);";
db.execSQL(createQuery);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
}
}
07-21 20:32:20.940: E/SQLiteLog(17813): (1) near "group": syntax error
07-21 20:32:20.955: W/dalvikvm(17813): threadid=11: thread exiting with uncaught exception (group=0x40e202a0)
07-21 20:32:21.000: E/AndroidRuntime(17813): FATAL EXCEPTION: AsyncTask #1
07-21 20:32:21.000: E/AndroidRuntime(17813): java.lang.RuntimeException: An error occured while executing doInBackground()
07-21 20:32:21.000: E/AndroidRuntime(17813): at android.os.AsyncTask$3.done(AsyncTask.java:299)
07-21 20:32:21.000: E/AndroidRuntime(17813): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
07-21 20:32:21.000: E/AndroidRuntime(17813): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
07-21 20:32:21.000: E/AndroidRuntime(17813): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
07-21 20:32:21.000: E/AndroidRuntime(17813): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
07-21 20:32:21.000: E/AndroidRuntime(17813): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
07-21 20:32:21.000: E/AndroidRuntime(17813): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
07-21 20:32:21.000: E/AndroidRuntime(17813): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
07-21 20:32:21.000: E/AndroidRuntime(17813): at java.lang.Thread.run(Thread.java:856)
07-21 20:32:21.000: E/AndroidRuntime(17813): Caused by: android.database.sqlite.SQLiteException: near "group": syntax error (code 1): , while compiling: CREATE TABLE exercises(_id integer primary key autoincrement,name TEXT, group TEXT, calory TEXT);
07-21 20:32:21.000: E/AndroidRuntime(17813): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
07-21 20:32:21.000: E/AndroidRuntime(17813): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1013)
07-21 20:32:21.000: E/AndroidRuntime(17813): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:624)
07-21 20:32:21.000: E/AndroidRuntime(17813): at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
07-21 20:32:21.000: E/AndroidRuntime(17813): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
07-21 20:32:21.000: E/AndroidRuntime(17813): at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
07-21 20:32:21.000: E/AndroidRuntime(17813): at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1663)
07-21 20:32:21.000: E/AndroidRuntime(17813): at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1594)
07-21 20:32:21.000: E/AndroidRuntime(17813): at com.abc. abc.DatabaseConnector$DatabaseOpenHelper.onCreate(DatabaseConnector.java:90)
07-21 20:32:21.000: E/AndroidRuntime(17813): at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252)
07-21 20:32:21.000: E/AndroidRuntime(17813): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
07-21 20:32:21.000: E/AndroidRuntime(17813): at com. abc. abc.DatabaseConnector.open(DatabaseConnector.java:26)
07-21 20:32:21.000: E/AndroidRuntime(17813): at com. abc. abc.Exercises_Main$Get_Ex_Data_Task.doInBackground(Exercises_Main.java:65)
07-21 20:32:21.000: E/AndroidRuntime(17813): at com. abc. abc.Exercises_Main$Get_Ex_Data_Task.doInBackground(Exercises_Main.java:1)
07-21 20:32:21.000: E/AndroidRuntime(17813): at android.os.AsyncTask$2.call(AsyncTask.java:287)
07-21 20:32:21.000: E/AndroidRuntime(17813): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
答案 0 :(得分:2)
group
是reserved word,不能在列名中使用。请将您的专栏命名为其他内容。
什么是堆栈跟踪?
Java堆栈跟踪是“Logcat:”部分中的内容,从您发布的LogCat条目末尾的java.lang.RuntimeException: An error occured while executing doInBackground()
行开始。