Kotlin: java.lang.ClassCastException: java.lang.Long 无法转换为 java.lang.Integer
Kotlin: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer
我知道有很多关于此异常的问题,但没有适合我的答案。
var count = sharedPref.getInt("flutter.badgeCount", 0) // line 12
ShortcutBadger.applyCount(applicationContext, count+1) // line 13
count
应该是一个整数,因为 sharedPref.getInt
returns 是一个整数,而 applyCount()
接收一个整数作为第二个参数。运行时在第 12 行抛出异常。
有什么我看不到的吗? (我对科特林还很陌生)
使用以下内容。这将解决问题。
var count = sharedPref.getLong("flutter.badgeCount", 0L)
ShortcutBadger.applyCount(applicationContext, count.toInt()+1)
我知道有很多关于此异常的问题,但没有适合我的答案。
var count = sharedPref.getInt("flutter.badgeCount", 0) // line 12
ShortcutBadger.applyCount(applicationContext, count+1) // line 13
count
应该是一个整数,因为 sharedPref.getInt
returns 是一个整数,而 applyCount()
接收一个整数作为第二个参数。运行时在第 12 行抛出异常。
有什么我看不到的吗? (我对科特林还很陌生)
使用以下内容。这将解决问题。
var count = sharedPref.getLong("flutter.badgeCount", 0L)
ShortcutBadger.applyCount(applicationContext, count.toInt()+1)