0

创建 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)
4

1 回答 1

2

group是一个保留字,不能用于列名。请将您的专栏命名为其他名称。

什么是堆栈跟踪?

Java 堆栈跟踪是您在“Logcat:”部分中的内容,从java.lang.RuntimeException: An error occured while executing doInBackground()您发布的 LogCat 条目末尾的行开始。

于 2013-07-21T12:46:01.023 回答