Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 393 Vote(s) - 3.54 Average
  • 1
  • 2
  • 3
  • 4
  • 5
(jetpack compose) androidx.compose.runtime.internal.ComposableLambdaImpl cannot be cast to kotlin.jvm.functions.Function0

#1
I have an BaseUi class for my custom views and my activities extends from it. <br/>
whe i using ```Root``` function , application crashed.

**BaseUi.kt**

@ExperimentalAnimationApi
open class BaseUi : AppCompatActivity() {

@Composable
fun RtlView(content: @Composable () -> Unit) {
CompositionLocalProvider(
LocalLayoutDirection provides LayoutDirection.Rtl,
content = content
)
}

@Composable
fun LtrView(content: @Composable () -> Unit) {
CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Ltr) {
content()
}
}

@Composable
fun Root(
content: @Composable () -> Unit
) {
KasbTheme {
Box(
Modifier
.fillMaxSize()
.background(LightPageBackground)
.padding(Dimen.pagePadding)
){
content()
}
}
}
}

**SplashActivity.kt**


@ExperimentalAnimationApi
class SplashActivity : BaseActivity() {

val viewModel = SplashActivityViewModel()

@ExperimentalAnimationApi
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
InitUI()
}
}

@ExperimentalAnimationApi
@Preview(showBackground = true)
@Composable
fun InitUI() {
Root {
RtlView {
Box(Modifier.fillMaxSize()) {
Image(
painter = painterResource(id = R.drawable.logo),
contentDescription = "",
modifier = Modifier.size(200.dp).align(Alignment.Center)
)
}
}
}
}
}

**Runtime error**

```
com.kasb.android E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.kasb.android, PID: 22387
java.lang.ClassCastException: androidx.compose.runtime.internal.ComposableLambdaImpl cannot be cast to kotlin.jvm.functions.Function0
at com.kasb.android.ui.activity.SplashActivity.InitUI(SplashActivity.kt:76)
at com.kasb.android.ui.activity.SplashActivity$onCreate$1.invoke(SplashActivity.kt:30)
at com.kasb.android.ui.activity.SplashActivity$onCreate$1.invoke(SplashActivity.kt:29)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at androidx.compose.ui.platform.ComposeView.Content(ComposeView.android.kt:384)
```
Reply

#2
not a permanent fix, but clean project gets rid of the error for one compile. Don't know why it's happening though.
Reply

#3
I had same error, and problem was caused that I was calling function form subtype of the class where it was defined

BaseActivity{
fun displayAlertDialog(content: @Composable() () -> Unit) {
bottomDialog.show(supportFragmentManager, "bottom-dialog")
bottomDialog.setContent(content)
}
@Composable
fun Screen(
activity: BaseActivity,
) {
activity.displayAlertDialog{}
}

// works fine
//if activity is subtype of BaseActivity it throws that error




Reply

#4
simple way, you just put the composable function into Class delegate,

``` in my ksp
writer.writeLine(${binding}.${handleMethod}(${IssueFixClass::class.simpleName}.${IssueFixClass.Delegate::makeClass.name}(contentListBlock$timestamp)))
```

result like this
```
binding.handleUIGroupCreator( IssueFixClass.makeClass(content64966723696806))
```



my kmm androidMain






```
actual class IssueFixClass private actual constructor(val content:@Composable @UiComposable ()->Unit){
@Composable
@UiComposable
actual fun invoke(){
content.invoke()
}
actual companion object Delegate{
actual fun makeClass(content: @Composable @UiComposable () -> Unit):IssueFixClass{
return IssueFixClass(content)
}
}
}
```
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through