英文:
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't add the accompanist pager dependency. Yes, We need both `androidx.compose.foundation` and `accompanist-pager` dependencies to use Pager views.
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论