どのようにこれらの問題を解決できますか?Android SQLiteデータベースCREATE TABLEエラー
プロセス:com.example.burhanozen.sqlitedb、PID:4658 android.database.sqlite.SQLiteException: "INTEGER" 周辺:構文エラー(コード1)、コンパイル中:表 students_table(IDを作成INTEGER PRIMARY KEY AUTOINCREMENT、名前テキスト、SURNAME TEXT、MARK INTEGER
com.example.burhanozen.sqlitedb.dbHelper.onCreate(dbHelper.kt:16)-at -at com.example.burhanozen.sqlitedb.dbHelper .insertData(dbHelper.kt:28) -at com.example.burhanozen.sqlitedb.MainActivity $ addData $ 1.onClick(MainActivity.kt:62)
これが主な活動です:
class MainActivity : AppCompatActivity() {
internal val helper = dbHelper(this)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
addData()
viewAll()
}
fun viewAll(){
kayitGoster.setOnClickListener{
val res = helper.allData
if(res.count == 0){
showMessage("Hata","Veri bulunamadı")
[email protected]
}
val buffer = StringBuffer()
while(res.moveToNext()){
buffer.append("Id : " + res.getString(0) + "\n")
buffer.append("Name : " + res.getString(1) + "\n")
buffer.append("Surname : " + res.getString(2) + "\n")
buffer.append("Mark : " + res.getString(3) + "\n")
}
}
}
fun showMessage(title:String, message:String){
val builder = AlertDialog.Builder(this)
builder.setCancelable(true)
builder.setTitle(title)
builder.setMessage(message)
builder.show()
}
fun addData(){
gonderButon.setOnClickListener {
helper.insertData(
editisim.text.toString(),
soyisim.text.toString(),
not.text.toString())
}
}
}
そして、ここではdbHelper.kt
class dbHelper (context : Context) : SQLiteOpenHelper(context,DATABASE_NAME,null,1) {
override fun onCreate(db: SQLiteDatabase) {
db.execSQL("CREATE TABLE $TABLE_NAME (ID INTEGER PRIMARY KEY AUTOINCREMENT," +
"NAME TEXT," +
"SURNAME TEXT," +
"MARK INTEGER")
}
override fun onUpgrade(db:SQLiteDatabase,oldVersion: Int, newVersion: Int){
db.execSQL("DROP TABLE IF EXISTS $TABLE_NAME")
onCreate(db)
}
fun insertData(name:String, surname:String, marks:String){
val db=this.writableDatabase
val contentValues = ContentValues()
contentValues.put(COL_NAME,name)
contentValues.put(COL_SURN,surname)
contentValues.put(COL_NOT,marks)
db.insert(TABLE_NAME,null,contentValues)
}
val allData: Cursor
get(){
val db=this.writableDatabase
val res=db.rawQuery("select * from $TABLE_NAME",null)
return res
}
companion object{
internal val DATABASE_NAME = "students.db"
internal val TABLE_NAME = "students_table"
internal val COL_ID = "ID"
internal val COL_NAME = "NAME"
internal val COL_SURN = "SURNAME"
internal val COL_NOT = "MARKS"
}
}
使用 'MARK INTEGER' https://sqlite.org/datatype3.html –