0

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)

Fabio
  • 376
  • 6
  • 19
  • 1
    You must have a long value stored in the shared preferences for that key. – Tenfour04 Dec 09 '20 at 18:29
  • "because sharedPref.getInt returns an integer" _if it succeeds_. In your case it fails, so the stored value is not an integer (and from the error message we know it's a long). Line 13 doesn't matter because you never get to there. – Alexey Romanov Dec 10 '20 at 13:24

1 Answers1

1

Use the following. This would solve the problem.

var count = sharedPref.getLong("flutter.badgeCount", 0L)  
ShortcutBadger.applyCount(applicationContext, count.toInt()+1)
Fabio
  • 376
  • 6
  • 19
akhil nair
  • 1,371
  • 1
  • 11
  • 19