Jetpack Compose HorizontalPager异常

huangapple go评论149阅读模式
英文:

Jetpack Compose HorizontalPager exception

问题

我在我的应用程序中使用了androidx.compose.foundation.pager中的HorizontalPager,我的函数的@Preview在交互模式下工作正常,但是当我运行应用程序时,我遇到了以下异常:

java.lang.NoSuchMethodError: No static method HorizontalPager-AlbwjTQ(ILandroidx/compose/ui/Modifier;Landroidx/compose/foundation/pager/PagerState;Landroidx/compose/foundation/layout/PaddingValues;Landroidx/compose/foundation/pager/PageSize;IFLandroidx/compose/ui/Alignment$Vertical;Landroidx/compose/foundation/gestures/snapping/SnapFlingBehavior;ZZLkotlin/jvm/functions/Function1;Landroidx/compose/ui/input/nestedscroll/NestedScrollConnection;Lkotlin/jvm/functions/Function3;Landroidx/compose/runtime/Composer;III)V in class Landroidx/compose/foundation/pager/PagerKt; or its super classes (declaration of 'androidx.compose.foundation.pager.PagerKt' appears in /data/app/~~KGVF3sYZNEP19lh8ZxkKbQ==/packagename-Uy9s9dyOAJmH_cCZaHyTLw==/base.apk)

我的代码:

val pages = lost.groupBy { it.pageNO }

HorizontalPager(pageCount = pages.size, beyondBoundsPageCount = 3) { index ->
    SomeComposeView(
        list = pages.get(index.plus(1))!!
    )
}

我的Compose依赖项:

compose-bom = "2023.06.01"
compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "compose-bom" }
compose-ui = { group = "androidx.compose.ui", name = "ui" }
compose-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" }
compose-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }
compose-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }
compose-foundation = { group = "androidx.compose.foundation", name = "foundation" }
compose-foundation-layout = { group = "androidx.compose.foundation", name = "foundation-layout" }
compose-runtime = { group = "androidx.compose.runtime", name = "runtime" }
compose-ui-util = { group = "androidx.compose.ui", name = "ui-util" }
material-icons-extended = { group = "androidx.compose.material", name = "material-icons-extended" }
ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
material-icons-core = { group = "androidx.compose.material", name = "material-icons-core" }
compose-material3 = { group = "androidx.compose.material3", name = "material3" }

希望这可以帮助到你解决问题。

英文:

I got crash when I used pager in my app

I used a HorizontalPager from androidx.compose.foundation.pager in my app. My function's @Preview work properly even in interaction mode, but when I run the app I got this exception:

java.lang.NoSuchMethodError: No static method HorizontalPager-AlbwjTQ(ILandroidx/compose/ui/Modifier;Landroidx/compose/foundation/pager/PagerState;Landroidx/compose/foundation/layout/PaddingValues;Landroidx/compose/foundation/pager/PageSize;IFLandroidx/compose/ui/Alignment$Vertical;Landroidx/compose/foundation/gestures/snapping/SnapFlingBehavior;ZZLkotlin/jvm/functions/Function1;Landroidx/compose/ui/input/nestedscroll/NestedScrollConnection;Lkotlin/jvm/functions/Function3;Landroidx/compose/runtime/Composer;III)V in class Landroidx/compose/foundation/pager/PagerKt; or its super classes (declaration of 'androidx.compose.foundation.pager.PagerKt' appears in /data/app/~~KGVF3sYZNEP19lh8ZxkKbQ==/packagename-Uy9s9dyOAJmH_cCZaHyTLw==/base.apk)

My code:

val pages = lost.groupBy { it.pageNO }

    HorizontalPager(pageCount = pages.size, beyondBoundsPageCount = 3) { index ->
        SomeComposeView(
            list = pages.get(index.plus(1))!!
        )
    }

My compose dependencies:

compose-bom = "2023.06.01"
compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "compose-bom" }
compose-ui = { group = "androidx.compose.ui", name = "ui" }
compose-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" }
compose-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }
compose-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }
compose-foundation = { group = "androidx.compose.foundation", name = "foundation" }
compose-foundation-layout = { group = "androidx.compose.foundation", name = "foundation-layout" }
compose-runtime = { group = "androidx.compose.runtime", name = "runtime" }
compose-ui-util = { group = "androidx.compose.ui", name = "ui-util" }
material-icons-extended = { group = "androidx.compose.material", name = "material-icons-extended" }
ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
material-icons-core = { group = "androidx.compose.material", name = "material-icons-core" }
compose-material3 = { group = "androidx.compose.material3", name = "material3" }```



</details>


# 答案1
**得分**: 1

经过3天的调查,我找到了问题所在。
导致应用程序崩溃的问题是我没有添加accompanist pager依赖项。是的,我们需要同时使用`androidx.compose.foundation`和`accompanist-pager`依赖项来使用Pager视图。

<details>
<summary>英文:</summary>

After 3 days I found the problem.
The problem that caused the app crash was I didn&#39;t add the accompanist pager dependency. Yes, We need both `androidx.compose.foundation` and `accompanist-pager` dependencies to use Pager views.

</details>



huangapple
  • 本文由 发表于 2023年8月9日 14:27:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76865105.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定