我试图将数据添加到SQLite,然后读取它,但是当我运行应用程序时,它的作用力关闭了。
这是我认为有问题的logcat的一部分
12-24 01:57:19.462 15349-15349 / com.eldarcreative.portalbola E / AndroidRuntime:FATAL EXCEPTION:main 流程:com.eldarcreative.portalbola,PID:15349 java.lang.RuntimeException:无法启动活动ComponentInfo {com.eldarcreative.portalbola / com.eldarcreative.portalbola.Favorit}:org.jetbrains.anko.AnkoException:com.eldarcreative.portalbola.Database.FavoriteTeam的类解析器无法解析行:
这是我的数据库代码
db.createTable(FavoriteTeam.TEAM_TABLE, true,
FavoriteTeam.ID to INTEGER + PRIMARY_KEY + AUTOINCREMENT,
FavoriteTeam.TEAM_ID to TEXT,
FavoriteTeam.STR_TEAM to TEXT,
FavoriteTeam.TEAM_BADGE to TEXT,
FavoriteTeam.TEAM_MANAGER to TEXT,
FavoriteTeam.STADIUM to TEXT,
FavoriteTeam.DESCRIPTION to TEXT,
FavoriteTeam.TEAM_BANNER to TEXT)
这里是我向数据库添加数据的代码
private fun addToFavorite() {
try {
database.use {
insert(
FavoriteTeam.TEAM_TABLE,
FavoriteTeam.TEAM_ID to id_team,
FavoriteTeam.STR_TEAM to txtdetailnama.text,
FavoriteTeam.TEAM_BADGE to strTeamBadge,
FavoriteTeam.TEAM_MANAGER to txtnamamanager.text,
FavoriteTeam.STADIUM to txtnamastadion.text,
FavoriteTeam.DESCRIPTION to teamOverview.text,
FavoriteTeam.TEAM_BANNER to strTeamBanner
)
}
toast ("Data Telah Di Simpan" )
} catch (e: SQLiteConstraintException) {
toast("Error: ${e.message}")
}
}
这是我尝试显示的代码
fun defaultfave(){
rvfavorite.layoutManager= GridLayoutManager(this,3)
database.use {
favoriteams.clear()
val hasil1 = select(FavoriteTeam.TEAM_TABLE)
val datafav1 = hasil1.parseList(classParser<FavoriteTeam>())
favoriteams.addAll(datafav1)
rvfavorite.adapter = FavoriteTeamAdapter(favoriteams)
}
最喜欢的团队是:-
@Parcelize
data class FavoriteTeam(
val id: Long?,
val idTeam: String,
val str_team : String,
val team_manager : String,
val stadium:String,
val deskription : String,
val team_baner:String,
val team_badge:String,
val urlImage: String
): Parcelable {
companion object {
const val TEAM_TABLE: String = "TEAM_TABLE"
const val ID: String = "ID_"
const val TEAM_ID: String = "TEAM_ID"
const val STR_TEAM:String="STR_TEAM"
const val TEAM_BADGE: String = "TEAM_BADGE"
const val TEAM_MANAGER:String ="TEAM_MANAGER"
const val STADIUM :String ="STADIUM"
const val DESCRIPTION:String ="DESCRIPTION"
const val TEAM_BANNER:String="TEAM_BANNER"
}
}
但是它失败了,任何人都知道为什么以及如何解决