很抱歉我问了个愚蠢的问题.
我用谷歌搜索了这个问题,但答案对我来说不适用.
这是我的密码.
data class Article(val id: Long, val title: String, val ingress: String, val image: String,
val dateTime: String, val tags: List<String>, val content: List<Item>, val created: Long, val changed: Long) {
@delegate:Transient
val formatDateString: String by lazy {
val sdf = SimpleDateFormat("dd.MM.yyyy HH.mm")
val date: Date = sdf.parse(dateTime)
var time: String?
if (date.year == Date().year) {
time = SimpleDateFormat("dd MM,HH:mm", Locale.US).format(date)
} else {
time = SimpleDateFormat("dd MM yyyy,HH:mm", Locale.US).format(date)
}
time!!
}
}
当我试图得到formatDateString
个值时,就会出现上述异常.
The codes access formatDateString
as following
override fun getCustomAdapter(): BaseQuickAdapter<CarListResponseBody.Article, BaseViewHolder> {
return object : BaseQuickAdapter<CarListResponseBody.Article, BaseViewHolder>( R.layout.app_item_cars_list,dataList) {
override fun convert(helper: BaseViewHolder, item: CarListResponseBody.Article) {
helper.setText(R.id.tv_ingress,item.ingress)
helper.setText(R.id.tv_date_time,item.formatDateString)
helper.setText(R.id.tv_title,item.title)
ImageLoadUtil.loadImgToView(context,item.image,helper.getView(R.id.img_car),null)
}
}
}
我认为这个异常是由Gson引起的,但我不知道为什么