Jetpack Compose HorizontalPager异常

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

Jetpack Compose HorizontalPager exception

问题

我在我的应用程序中使用分页器时出现了崩溃

我在我的应用程序中使用了来自androidx.compose.foundation.pagerHorizontalPager。我的@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-2.html
匿名

发表评论

匿名网友

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

确定