简体   繁体   中英

Fatal Exception: java.lang.IllegalArgumentException offset(23) is out of bounds [0, 0] JetPack Compose OutlinedTextField

Facing one crash in the jetpack compose, can anyone please help me with this.

Fatal Exception: java.lang.IllegalArgumentException: offset(23) is out of bounds [0, 0]
   at androidx.compose.ui.text.MultiParagraph.requireIndexInRangeInclusiveEnd(MultiParagraph.kt:593)
   at androidx.compose.ui.text.MultiParagraph.getBidiRunDirection(MultiParagraph.kt:406)
   at androidx.compose.ui.text.TextLayoutResult.getBidiRunDirection(TextLayoutResult.kt:353)
   at androidx.compose.foundation.text.CoreTextFieldKt.SelectionToolbarAndHandles(CoreTextField.kt:816)
   at androidx.compose.foundation.text.CoreTextFieldKt.access$SelectionToolbarAndHandles(CoreTextField.kt:1)
   at androidx.compose.foundation.text.CoreTextFieldKt$CoreTextField$4$1$1.invoke(CoreTextField.kt:565)
   at androidx.compose.foundation.text.CoreTextFieldKt$CoreTextField$4$1$1.invoke(CoreTextField.kt:527)
   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.runtime.ComposablesKt.ReusableComposeNode(ComposablesKt.java:443)
   at androidx.compose.foundation.text.selection.SimpleLayoutKt.SimpleLayout(SimpleLayout.kt:79)
   at androidx.compose.foundation.text.CoreTextFieldKt$CoreTextField$4$1.invoke(CoreTextField.kt:527)
   at androidx.compose.foundation.text.CoreTextFieldKt$CoreTextField$4$1.invoke(CoreTextField.kt:510)
   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.material.OutlinedTextFieldKt.IconsWithTextFieldLayout-T2E5_Oc(OutlinedTextField.kt:452)
   at androidx.compose.material.OutlinedTextFieldKt.access$OutlinedTextField$lambda-3(OutlinedTextField.kt:1)
   at androidx.compose.material.OutlinedTextFieldKt$OutlinedTextFieldLayout$1.invoke(OutlinedTextField.kt:350)
   at androidx.compose.material.OutlinedTextFieldKt$OutlinedTextFieldLayout$1.invoke(OutlinedTextField.kt:348)
   at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:116)
   at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
   at androidx.compose.foundation.text.CoreTextFieldKt.CoreTextField(CoreTextField.kt:510)
   at androidx.compose.foundation.text.BasicTextFieldKt.BasicTextField(BasicTextField.kt:262)
   at androidx.compose.material.OutlinedTextFieldKt.OutlinedTextFieldLayout-uBqXD2s(OutlinedTextField.kt:322)
   at androidx.compose.material.TextFieldImplKt$TextFieldImpl$3.invoke-h1eT-Ww(TextFieldImpl.kt:207)
   at androidx.compose.material.TextFieldImplKt$TextFieldImpl$3.invoke(TextFieldImpl.kt:129)
   at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:214)
   at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
   at androidx.compose.material.TextFieldTransitionScope.Transition-DTcfvLk(TextFieldImpl.kt:357)
   at androidx.compose.material.TextFieldImplKt.TextFieldImpl(TextFieldImpl.kt:119)
   at androidx.compose.material.OutlinedTextFieldKt.OutlinedTextField(OutlinedTextField.kt:270)
   at androidx.compose.material.OutlinedTextFieldKt.OutlinedTextField(OutlinedTextField.kt:157)
   at com.zee5.presentation.search.searchrefinement.composable.SearchRefinementScreenKt.TopTextInputView(SearchRefinementScreen.kt:131)
   at com.zee5.presentation.search.searchrefinement.composable.SearchRefinementScreenKt.SearchRefinementScreen(SearchRefinementScreen.kt:74)
   at com.zee5.presentation.search.searchrefinement.fragment.SearchRefinementFragment$onCreateView$1$1.invoke(SearchRefinementFragment.kt:60)
   at com.zee5.presentation.search.searchrefinement.fragment.SearchRefinementFragment$onCreateView$1$1.invoke(SearchRefinementFragment.kt:56)
   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.runtime.RecomposeScopeImpl.compose(RecomposeScopeImpl.kt:140)
   at androidx.compose.runtime.ComposerImpl.recomposeToGroupEnd(Composer.kt:2158)
   at androidx.compose.runtime.ComposerImpl.skipCurrentGroup(Composer.kt:2404)
   at androidx.compose.runtime.ComposerImpl$doCompose$2$5.invoke(Composer.kt:2585)
   at androidx.compose.runtime.ComposerImpl$doCompose$2$5.invoke(Composer.kt:2571)
   at androidx.compose.runtime.SnapshotStateKt__DerivedStateKt.observeDerivedStateRecalculations(DerivedState.kt:247)
   at androidx.compose.runtime.SnapshotStateKt.observeDerivedStateRecalculations(SnapshotStateKt.java:1)
   at androidx.compose.runtime.ComposerImpl.doCompose(Composer.kt:2571)
   at androidx.compose.runtime.ComposerImpl.recompose$runtime_release(Composer.kt:2547)
   at androidx.compose.runtime.CompositionImpl.recompose(Composition.kt:620)
   at androidx.compose.runtime.Recomposer.performRecompose(Recomposer.kt:786)
   at androidx.compose.runtime.Recomposer.access$setCloseCause$p(Recomposer.kt:105)
   at androidx.compose.runtime.Recomposer$runRecomposeAndApplyChanges$2$2.invoke(Recomposer.kt:456)
   at androidx.compose.runtime.Recomposer$runRecomposeAndApplyChanges$2$2.invoke(Recomposer.kt:425)
   at androidx.compose.ui.platform.AndroidUiFrameClock$withFrameNanos$2$callback$1.doFrame(AndroidUiFrameClock.android.kt:34)
   at androidx.compose.ui.platform.AndroidUiDispatcher.performFrameDispatch(AndroidUiDispatcher.android.kt:109)
   at androidx.compose.ui.platform.AndroidUiDispatcher.access$setScheduledFrameDispatch$p(AndroidUiDispatcher.android.kt:41)
   at androidx.compose.ui.platform.AndroidUiDispatcher$dispatchCallback$1.doFrame(AndroidUiDispatcher.android.kt:69)
   at android.view.Choreographer$CallbackRecord.run(Choreographer.java:947)
   at android.view.Choreographer.doCallbacks(Choreographer.java:761)
   at android.view.Choreographer.doFrame(Choreographer.java:693)
   at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:935)
   at android.os.Handler.handleCallback(Handler.java:873)
   at android.os.Handler.dispatchMessage(Handler.java:99)
   at android.os.Looper.loop(Looper.java:193)
   at android.app.ActivityThread.main(ActivityThread.java:6953)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:590)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

This is probably not a problem with Firebase, but a problem with displaying your data, in particular with the offset mapping. Do you use some kind of visual transformation? https://developer.android.com/reference/kotlin/androidx/compose/ui/text/input/VisualTransformation

(I'd like rather to put this in the comments, but I'm not allowed to comment yet)

We receive these crash logs regularly with Compose 1.1.1 and TextField using visual transformation. The problem was a dynamic change of visual transformation from VisualTransformation.None to our custom one after the user long pressed on input with some value inside it. And because we change that in onFocusEvent if FocusState.isFocused == true then race condition occurred somewhere in the TextField .

Our solution was to change visual transformation also on initial value change using value key inside remember statement

val ourCustomTransformation = remember {
    OurCustomTransformation()
}

var visualTransformation by remember(value) {
    mutableStateOf(
        if (value.isBlank()) {
            VisualTransformation.None
        } else {
            ourCustomTransformation
        }
    )
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM