Home » Android » Solved: java.lang.ClassCastException: android.app.ContextImpl cannot be cast to android.app.Activity

Solved: java.lang.ClassCastException: android.app.ContextImpl cannot be cast to android.app.Activity

If you are working on Android application or AAR Library, you will be using applications context frequently for accessing android system API’s.While using those API’s which are dependent on Context, there are chances you may see an error like as below,

System.err: java.lang.ClassCastException: android.app.ContextImpl cannot be cast to android.app.Activity

Solution :

When we encountered this error in to accessing one of our library, we were passing Context to library API using getBaseContext() API whereas our library was expecting application context, hence solution which worked was,

Change getBaseContext() to “this” while calling the library function.


Subscribe our Rurban Life YouTube Channel.. "Rural Life, Urban LifeStyle"

1 thought on “Solved: java.lang.ClassCastException: android.app.ContextImpl cannot be cast to android.app.Activity”

Leave a Comment