fabio
fabio

Reputation: 466

Kotlin: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer

I know there are a lot of questions about this exception but no answer suited my case.

var count = sharedPref.getInt("flutter.badgeCount", 0)    // line 12
ShortcutBadger.applyCount(applicationContext, count+1)    // line 13

count should be an integer because sharedPref.getInt returns an integer, and applyCount() receive an integer as the second parameter. The exception is thrown at runtime at line 12. Is there anything I can't see? (I'm pretty new to kotlin)

Upvotes: 0

Views: 4610

Answers (1)

akhil nair
akhil nair

Reputation: 1551

Use the following. This would solve the problem.

var count = sharedPref.getLong("flutter.badgeCount", 0L)  
ShortcutBadger.applyCount(applicationContext, count.toInt()+1)

Upvotes: 2

Related Questions