嘿伙计们,我希望你能帮助我。
我收到此错误但无法找到解决问题的方法
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sergej.myapplication4/com.sergej.slidnerd_kopie.training.MeinePlaene_main}: android.database.sqlite.SQLiteException: near "SETSworkout": syntax error (code 1): , while compiling: CREATE SETSworkout(name TEXT)
这是我的创建表
public class WorkoutDataHelper extends SQLiteOpenHelper {
public static final int DB_VERSION = 2;
public static final String DB_NAME = "dmworkouts.db";
public static final String WORKOUT_TABLE_NAME = "workouts";
public static final String SETS_TABLE_NAME = "workouts";
public static final String SESSIONS_TABLE_NAME = "sessions";
public static final String CREATE_WORKOUT_TABLE = "CREATE TABLE " + WORKOUT_TABLE_NAME +
" ( name TEXT )";
public static final String CREATE_SETS_TABLE ="CREATE SETS"+SETS_TABLE_NAME+"(name TEXT)";
public static final String CREATE_SESSIONS_TABLE = "CREATE TABLE " + SESSIONS_TABLE_NAME +
" ( time INTEGER, workoutid INTEGER, type INTEGER)";
public WorkoutDataHelper(Context context) {
super(context,DB_NAME, null, DB_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_WORKOUT_TABLE);
db.execSQL(CREATE_SETS_TABLE);
db.execSQL(CREATE_SESSIONS_TABLE);
}
}
我认为这个问题出现在CREATE_WORKOUT_TABLE
,但我试图解决它,但我没有做到。
答案 0 :(得分:1)
连接字符串时缺少空格:
"CREATE SETS"+SETS_TABLE_NAME+"(name TEXT)"
应该是:
"CREATE SETS "+SETS_TABLE_NAME+"(name TEXT)"
因此给出了错误。您可以在错误消息中看到单词SET
未与表名分开,使其成为一个单词,使该语句无效。