Home > Mobile >  java.lang.ClassCastException: com.compose.MainActivity cannot be cast to androidx.fragment.app.Fragm
java.lang.ClassCastException: com.compose.MainActivity cannot be cast to androidx.fragment.app.Fragm

Time:10-23

I am trying to integrate BiometricPrompt with Jetpackcompose

Here is a snippet of my code which is called on a button click

val context = LocalContext.current
val biometricPrompt =BiometricPrompt(context as FragmentActivity,ContextCompat.getMainExecutor(context),object : BiometricPrompt.AuthenticationCallback() {.....

The error is context as FragmentActivity, not sure how to and what to cast the context as. I tried Activity, ComponentActivity as well.

As soon as i click the button i get error saying

java.lang.ClassCastException: com.compose.MainActivity cannot be cast to androidx.fragment.app.FragmentActivity

I tried looking in to enter image description here

Check your MainActivity class.
It should extend AppCompatActivity or FragmentActivity instead of ComponentActivity.

  • Related