So I am currently working on a spinner that changes entries in a list. When loading into the Fragment and loading the List into the spinner adapter and setting up the onItemChangedListener everything works fine. But when the App goes to another Fragment and then goes back the app crashes with the following exception:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: de.heffnersoftware.hsproduction, PID: 13111
java.lang.NullPointerException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkNotNullParameter, parameter view
at de.heffnersoftware.hsproduction.ui.storeManagement.ListFiveFragment$onCreateView$3.onItemSelected(Unknown Source:2)
at android.widget.AdapterView.fireOnSelected(AdapterView.java:957)
at android.widget.AdapterView.dispatchOnItemSelected(AdapterView.java:946)
at android.widget.AdapterView.selectionChanged(AdapterView.java:935)
at android.widget.AdapterView.checkSelectionChanged(AdapterView.java:1118)
at android.widget.AdapterView.handleDataChanged(AdapterView.java:1094)
at android.widget.AbsSpinner.onMeasure(AbsSpinner.java:193)
at android.widget.Spinner.onMeasure(Spinner.java:614)
at androidx.appcompat.widget.AppCompatSpinner.onMeasure(AppCompatSpinner.java:438)
at android.view.View.measure(View.java:24721)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:735)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:481)
at android.view.View.measure(View.java:24721)
at androidx.constraintlayout.widget.ConstraintLayout$Measurer.measure(ConstraintLayout.java:811)
at androidx.constraintlayout.core.widgets.analyzer.BasicMeasure.measure(BasicMeasure.java:466)
at androidx.constraintlayout.core.widgets.analyzer.BasicMeasure.measureChildren(BasicMeasure.java:134)
at androidx.constraintlayout.core.widgets.analyzer.BasicMeasure.solverMeasure(BasicMeasure.java:278)
at androidx.constraintlayout.core.widgets.ConstraintWidgetContainer.measure(ConstraintWidgetContainer.java:120)
at androidx.constraintlayout.widget.ConstraintLayout.resolveSystem(ConstraintLayout.java:1594)
at androidx.constraintlayout.widget.ConstraintLayout.onMeasure(ConstraintLayout.java:1708)
at android.view.View.measure(View.java:24721)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6903)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.view.View.measure(View.java:24721)
at androidx.constraintlayout.widget.ConstraintLayout$Measurer.measure(ConstraintLayout.java:811)
at androidx.constraintlayout.core.widgets.analyzer.BasicMeasure.measure(BasicMeasure.java:466)
at androidx.constraintlayout.core.widgets.analyzer.BasicMeasure.measureChildren(BasicMeasure.java:134)
at androidx.constraintlayout.core.widgets.analyzer.BasicMeasure.solverMeasure(BasicMeasure.java:278)
at androidx.constraintlayout.core.widgets.ConstraintWidgetContainer.measure(ConstraintWidgetContainer.java:120)
at androidx.constraintlayout.widget.ConstraintLayout.resolveSystem(ConstraintLayout.java:1594)
at androidx.constraintlayout.widget.ConstraintLayout.onMeasure(ConstraintLayout.java:1708)
at android.view.View.measure(View.java:24721)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6903)
at androidx.coordinatorlayout.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:760)
at com.google.android.material.appbar.HeaderScrollingViewBehavior.onMeasureChild(HeaderScrollingViewBehavior.java:99)
at com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior.onMeasureChild(AppBarLayout.java:2227)
at androidx.coordinatorlayout.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:831)
at android.view.View.measure(View.java:24721)
at androidx.drawerlayout.widget.DrawerLayout.onMeasure(DrawerLayout.java:1156)
at android.view.View.measure(View.java:24721)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6903)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at androidx.appcompat.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:145)
at android.view.View.measure(View.java:24721)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6903)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1552)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:842)
E/AndroidRuntime: at android.widget.LinearLayout.onMeasure(LinearLayout.java:721)
at android.view.View.measure(View.java:24721)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6903)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.view.View.measure(View.java:24721)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6903)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1552)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:842)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:721)
at android.view.View.measure(View.java:24721)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6903)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at com.android.internal.policy.DecorView.onMeasure(DecorView.java:743)
at android.view.View.measure(View.java:24721)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:3135)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1900)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2200)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1788)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7867)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:967)
at android.view.Choreographer.doCallbacks(Choreographer.java:791)
at android.view.Choreographer.doFrame(Choreographer.java:726)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:952)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7399)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:502)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:980)
Bellow is the Listener and code surrounding it:
val spinner: Spinner = root.findViewById(R.id.store_select_spinner)
val spinnerAdapter: ArrayAdapter<String> = ArrayAdapter(
requireContext(), R.layout.spinner_item, llNames
)
spinnerAdapter.setDropDownViewResource(R.layout.spinner_item)
spinner.adapter = spinnerAdapter
spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(
parent: AdapterView<*>?,
view: View,
position: Int,
id: Long
) {
}
override fun onNothingSelected(parent: AdapterView<*>?) {
}
}
The error has been solved by the solution Demigod provided.
The code needs to be altered as the following:
spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(
parent: AdapterView<*>?,
view: View?,
position: Int,
id: Long
) {
StoreListFragment.storeAdapter.changeShelve(llShelveNames[position].first)
}
override fun onNothingSelected(parent: AdapterView<*>?) {
}
}
Related
Let's say I have a LazyColumn with Text field and button to toggle is the text field available or not.
LazyColumn() {
item {
var text by remember { mutableStateOf("Hello") }
if (myViewModel.showTextField.value) {
TextField(value = text, onValueChange = { text = it })
}
TextButton(onClick = { myViewModel.toggleField() }) {
Text(text = "toggle")
}
}
}
And viewModel has code like this
class MyViewModel : ViewModel() {
private val _showTextField = mutableStateOf(true)
val showTextField : State<Boolean> = _showTextField
fun toggleField() {
_showTextField.value = !showTextField.value
}
}
And now when I click on TextField before clicking toggle button. So TextField has focus before removing it, the application crashes with following error:
2022-04-09 19:43:03.417 12336-12336/com.courtesy.test E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.courtesy.test, PID: 12336
java.lang.IllegalStateException: LayoutCoordinates androidx.compose.ui.node.ModifierLocalConsumerNode#bab1d96 is not attached!
at androidx.compose.ui.node.LayoutNodeWrapper.localBoundingBoxOf(LayoutNodeWrapper.kt:714)
at androidx.compose.foundation.gestures.ContentInViewModifier.onSizeChanged-O0kMr_c(Scrollable.kt:524)
at androidx.compose.foundation.gestures.ContentInViewModifier.onRemeasured-ozmzZPI(Scrollable.kt:492)
at androidx.compose.ui.node.LayoutNodeWrapper$onMeasured$invokeRemeasureCallbacks$1.invoke(LayoutNodeWrapper.kt:244)
at androidx.compose.ui.node.LayoutNodeWrapper$onMeasured$invokeRemeasureCallbacks$1.invoke(LayoutNodeWrapper.kt:242)
at androidx.compose.runtime.snapshots.SnapshotStateObserver.withNoObservations(SnapshotStateObserver.kt:142)
at androidx.compose.ui.node.OwnerSnapshotObserver.withNoSnapshotReadObservation$ui_release(OwnerSnapshotObserver.kt:55)
at androidx.compose.ui.node.LayoutNodeWrapper.onMeasured(LayoutNodeWrapper.kt:247)
at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.measure-BRTryo0(DelegatingLayoutNodeWrapper.kt:107)
at androidx.compose.ui.graphics.SimpleGraphicsLayerModifier.measure-3p2s80s(GraphicsLayerModifier.kt:405)
at androidx.compose.ui.node.ModifiedLayoutNode.measure-BRTryo0(ModifiedLayoutNode.kt:40)
at androidx.compose.ui.node.LayoutNode$performMeasure$1.invoke(LayoutNode.kt:1342)
at androidx.compose.ui.node.LayoutNode$performMeasure$1.invoke(LayoutNode.kt:1341)
at androidx.compose.runtime.snapshots.Snapshot$Companion.observe(Snapshot.kt:1918)
at androidx.compose.runtime.snapshots.SnapshotStateObserver.observeReads(SnapshotStateObserver.kt:121)
at androidx.compose.ui.node.OwnerSnapshotObserver.observeReads$ui_release(OwnerSnapshotObserver.kt:88)
at androidx.compose.ui.node.OwnerSnapshotObserver.observeMeasureSnapshotReads$ui_release(OwnerSnapshotObserver.kt:76)
at androidx.compose.ui.node.LayoutNode.performMeasure-BRTryo0$ui_release(LayoutNode.kt:1341)
at androidx.compose.ui.node.OuterMeasurablePlaceable.remeasure-BRTryo0(OuterMeasurablePlaceable.kt:94)
at androidx.compose.ui.node.LayoutNode.remeasure-_Sx5XlM$ui_release(LayoutNode.kt:1295)
at androidx.compose.ui.node.LayoutNode.remeasure-_Sx5XlM$ui_release$default(LayoutNode.kt:1291)
at androidx.compose.ui.node.MeasureAndLayoutDelegate.doRemeasure-sdFAvZA(MeasureAndLayoutDelegate.kt:180)
at androidx.compose.ui.node.MeasureAndLayoutDelegate.remeasureAndRelayoutIfNeeded(MeasureAndLayoutDelegate.kt:256)
at androidx.compose.ui.node.MeasureAndLayoutDelegate.access$remeasureAndRelayoutIfNeeded(MeasureAndLayoutDelegate.kt:36)
at androidx.compose.ui.node.MeasureAndLayoutDelegate.measureAndLayout(MeasureAndLayoutDelegate.kt:201)
at androidx.compose.ui.platform.AndroidComposeView.onMeasure(AndroidComposeView.android.kt:756)
at android.view.View.measure(View.java:25466)
at androidx.compose.ui.platform.AbstractComposeView.internalOnMeasure$ui_release(ComposeView.android.kt:298)
at androidx.compose.ui.platform.AbstractComposeView.onMeasure(ComposeView.android.kt:285)
at android.view.View.measure(View.java:25466)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6957)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at androidx.appcompat.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:145)
at android.view.View.measure(View.java:25466)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6957)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1552)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:842)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:721)
at android.view.View.measure(View.java:25466)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6957)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.view.View.measure(View.java:25466)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6957)
2022-04-09 19:43:03.418 12336-12336/com.courtesy.test E/AndroidRuntime: at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1552)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:842)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:721)
at android.view.View.measure(View.java:25466)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6957)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at com.android.internal.policy.DecorView.onMeasure(DecorView.java:747)
at android.view.View.measure(View.java:25466)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:3397)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:2228)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2486)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1952)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8171)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:972)
at android.view.Choreographer.doCallbacks(Choreographer.java:796)
at android.view.Choreographer.doFrame(Choreographer.java:731)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:957)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
2022-04-09 19:43:03.816 12336-12336/com.courtesy.test I/Process: Sending signal. PID: 12336 SIG: 9
It works fine when I don't click the TextField before clicking the button.
And also everything works correctly if I use Column instead of LazyColumn.
Any ideas how to solve this issue?
Fixed by changing compose version from 1.2.0-alpha06 to 1.2.0-alpha07
I am developing a dummy weather app with the help of Kotlin Multiplatform. I am using Decompose and MVIKotlin to try and share all the business logic except the native uis, SwiftUI for IOS and Compose for Desktop and Android.
I am trying to have a expect composable (for dark theme and for loading of images)
// In common main
#Composable
expect fun isDarkMode() : Boolean
#Composable
expect fun loadWeatherIcon(id : Int) : Painter
// In android main
#Composable
actual fun isDarkMode() : Boolean {
return androidx.compose.foundation.isSystemInDarkTheme()
}
#Composable
actual fun loadWeatherIcon(id : Int) : Painter {
return painterResource(id)
}
//In Desktop main
#Composable
actual fun isDarkMode() : Boolean {
return false //isSystemInDarkTheme()
}
#Composable
actual fun loadWeatherIcon(id : Int) : Painter {
return loadWeatherIcon(id)
}
Meaning they are all implemented and there, but for some reason the crash is happening with NoSuchMethodError. I found some similar issues but they all had suspend funs and default parameters. Meanwhile my approach should work like in the jetpack todo compose sample, here's my project (if you want to test what's happening, you can just clone it and run it, it should crash immediatelly)
https://github.com/Nikola-Milovic/KotlinMultiplaftorm-WeatherApp
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.nikolam.kmm_weather.androidApp, PID: 17270
java.lang.NoSuchMethodError: No static method isDarkMode(Landroidx/compose/runtime/Composer;I)Z in class Lcom/nikolam/kmm_weather/ui/UtilsKt; or its super classes (declaration of 'com.nikolam.kmm_weather.ui.UtilsKt' appears in /data/data/com.nikolam.kmm_weather.androidApp/code_cache/.overlay/base.apk/classes4.dex)
at com.nikolam.kmm_weather.ui.WeatherMainContentKt$WeatherMainContent$2.invoke(WeatherMainContent.kt:45)
at com.nikolam.kmm_weather.ui.WeatherMainContentKt$WeatherMainContent$2.invoke(WeatherMainContent.kt:38)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:109)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:193)
at com.nikolam.kmm_weather.ui.WeatherMainContentKt.WeatherMainContent(WeatherMainContent.kt:38)
at com.nikolam.kmm_weather.ui.ComposableSingletons$WeatherRootContentKt$lambda-1$1.invoke(WeatherRootContent.kt:14)
at com.nikolam.kmm_weather.ui.ComposableSingletons$WeatherRootContentKt$lambda-1$1.invoke(WeatherRootContent.kt:12)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:118)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at com.arkivanov.decompose.extensions.compose.jetbrains.ChildrenKt$Children$1$1.invoke(Children.kt:30)
at com.arkivanov.decompose.extensions.compose.jetbrains.ChildrenKt$Children$1$1.invoke(Children.kt:29)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:109)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:193)
at androidx.compose.runtime.saveable.SaveableStateHolderImpl.SaveableStateProvider(SaveableStateHolder.kt:84)
at com.arkivanov.decompose.extensions.compose.jetbrains.ChildrenKt$Children$1.invoke(Children.kt:29)
at com.arkivanov.decompose.extensions.compose.jetbrains.ChildrenKt$Children$1.invoke(Children.kt:28)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:118)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at com.arkivanov.decompose.extensions.compose.jetbrains.animation.page.PageAnimationKt$PageAnimationFrame$1$1$1.invoke(PageAnimation.kt:143)
at com.arkivanov.decompose.extensions.compose.jetbrains.animation.page.PageAnimationKt$PageAnimationFrame$1$1$1.invoke(PageAnimation.kt:141)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:118)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at com.arkivanov.decompose.extensions.compose.jetbrains.animation.child.CrossfadeScaleKt$crossfadeScale$1.invoke(CrossfadeScale.kt:22)
at com.arkivanov.decompose.extensions.compose.jetbrains.animation.child.CrossfadeScaleKt$crossfadeScale$1.invoke(CrossfadeScale.kt:21)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:254)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at com.arkivanov.decompose.extensions.compose.jetbrains.animation.page.PageAnimationKt$PageAnimationFrame$1.invoke(PageAnimation.kt:141)
at com.arkivanov.decompose.extensions.compose.jetbrains.animation.page.PageAnimationKt$PageAnimationFrame$1.invoke(PageAnimation.kt:132)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:118)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at androidx.compose.foundation.layout.BoxWithConstraintsKt$BoxWithConstraints$1$1$measurables$1.invoke(BoxWithConstraints.kt:61)
E/AndroidRuntime: at androidx.compose.foundation.layout.BoxWithConstraintsKt$BoxWithConstraints$1$1$measurables$1.invoke(BoxWithConstraints.kt:61)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:109)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at androidx.compose.ui.layout.SubcomposeLayoutState$subcompose$2$1.invoke(SubcomposeLayout.kt:167)
at androidx.compose.ui.layout.SubcomposeLayoutState$subcompose$2$1.invoke(SubcomposeLayout.kt:167)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:109)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at androidx.compose.runtime.ComposerKt.invokeComposable(Composer.kt:3235)
at androidx.compose.runtime.ComposerImpl.doCompose(Composer.kt:2514)
at androidx.compose.runtime.ComposerImpl.composeContent$runtime_debug(Composer.kt:2478)
at androidx.compose.runtime.CompositionImpl.composeContent(Composition.kt:453)
at androidx.compose.runtime.Recomposer.composeInitial$runtime_debug(Recomposer.kt:702)
at androidx.compose.runtime.ComposerImpl$CompositionContextImpl.composeInitial$runtime_debug(Composer.kt:2914)
at androidx.compose.runtime.CompositionImpl.setContent(Composition.kt:409)
at androidx.compose.ui.layout.SubcomposeLayoutState.subcomposeInto(SubcomposeLayout.kt:184)
at androidx.compose.ui.layout.SubcomposeLayoutState.access$subcomposeInto(SubcomposeLayout.kt:100)
at androidx.compose.ui.layout.SubcomposeLayoutState$subcompose$2.invoke(SubcomposeLayout.kt:160)
at androidx.compose.ui.layout.SubcomposeLayoutState$subcompose$2.invoke(SubcomposeLayout.kt:158)
at androidx.compose.runtime.snapshots.SnapshotStateObserver.withNoObservations(SnapshotStateObserver.kt:137)
at androidx.compose.ui.node.OwnerSnapshotObserver.withNoSnapshotReadObservation$ui_debug(OwnerSnapshotObserver.kt:49)
at androidx.compose.ui.node.LayoutNode.withNoSnapshotReadObservation$ui_debug(LayoutNode.kt:1054)
at androidx.compose.ui.layout.SubcomposeLayoutState.subcompose(SubcomposeLayout.kt:158)
at androidx.compose.ui.layout.SubcomposeLayoutState.subcompose(SubcomposeLayout.kt:152)
at androidx.compose.foundation.layout.BoxWithConstraintsKt$BoxWithConstraints$1$1.invoke-0kLqBqw(BoxWithConstraints.kt:61)
at androidx.compose.foundation.layout.BoxWithConstraintsKt$BoxWithConstraints$1$1.invoke(BoxWithConstraints.kt:59)
at androidx.compose.ui.layout.SubcomposeLayoutState$createMeasurePolicy$1.measure-3p2s80s(SubcomposeLayout.kt:212)
at androidx.compose.ui.node.InnerPlaceable.measure-BRTryo0(InnerPlaceable.kt:45)
at androidx.compose.ui.node.OuterMeasurablePlaceable$remeasure$2.invoke(OuterMeasurablePlaceable.kt:95)
at androidx.compose.ui.node.OuterMeasurablePlaceable$remeasure$2.invoke(OuterMeasurablePlaceable.kt:94)
at androidx.compose.runtime.snapshots.SnapshotStateObserver.observeReads(SnapshotStateObserver.kt:121)
at androidx.compose.ui.node.OwnerSnapshotObserver.observeReads$ui_debug(OwnerSnapshotObserver.kt:75)
at androidx.compose.ui.node.OwnerSnapshotObserver.observeMeasureSnapshotReads$ui_debug(OwnerSnapshotObserver.kt:63)
at androidx.compose.ui.node.OuterMeasurablePlaceable.remeasure-BRTryo0(OuterMeasurablePlaceable.kt:94)
at androidx.compose.ui.node.OuterMeasurablePlaceable.measure-BRTryo0(OuterMeasurablePlaceable.kt:68)
at androidx.compose.ui.node.LayoutNode.measure-BRTryo0(LayoutNode.kt:1172)
at androidx.compose.foundation.layout.BoxKt$boxMeasurePolicy$1.measure-3p2s80s(Box.kt:111)
at androidx.compose.ui.node.InnerPlaceable.measure-BRTryo0(InnerPlaceable.kt:45)
at androidx.compose.ui.graphics.SimpleGraphicsLayerModifier.measure-3p2s80s(GraphicsLayerModifier.kt:213)
at androidx.compose.ui.node.ModifiedLayoutNode.measure-BRTryo0(ModifiedLayoutNode.kt:37)
at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.measure-BRTryo0(DelegatingLayoutNodeWrapper.kt:108)
E/AndroidRuntime: at androidx.compose.ui.graphics.SimpleGraphicsLayerModifier.measure-3p2s80s(GraphicsLayerModifier.kt:213)
at androidx.compose.ui.node.ModifiedLayoutNode.measure-BRTryo0(ModifiedLayoutNode.kt:37)
at androidx.compose.ui.node.OuterMeasurablePlaceable$remeasure$2.invoke(OuterMeasurablePlaceable.kt:95)
at androidx.compose.ui.node.OuterMeasurablePlaceable$remeasure$2.invoke(OuterMeasurablePlaceable.kt:94)
at androidx.compose.runtime.snapshots.SnapshotStateObserver.observeReads(SnapshotStateObserver.kt:121)
at androidx.compose.ui.node.OwnerSnapshotObserver.observeReads$ui_debug(OwnerSnapshotObserver.kt:75)
at androidx.compose.ui.node.OwnerSnapshotObserver.observeMeasureSnapshotReads$ui_debug(OwnerSnapshotObserver.kt:63)
at androidx.compose.ui.node.OuterMeasurablePlaceable.remeasure-BRTryo0(OuterMeasurablePlaceable.kt:94)
at androidx.compose.ui.node.OuterMeasurablePlaceable.measure-BRTryo0(OuterMeasurablePlaceable.kt:68)
at androidx.compose.ui.node.LayoutNode.measure-BRTryo0(LayoutNode.kt:1172)
at androidx.compose.ui.layout.RootMeasurePolicy.measure-3p2s80s(RootMeasurePolicy.kt:38)
at androidx.compose.ui.node.InnerPlaceable.measure-BRTryo0(InnerPlaceable.kt:45)
at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.measure-BRTryo0(DelegatingLayoutNodeWrapper.kt:108)
at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.measure-BRTryo0(DelegatingLayoutNodeWrapper.kt:108)
at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.measure-BRTryo0(DelegatingLayoutNodeWrapper.kt:108)
at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.measure-BRTryo0(DelegatingLayoutNodeWrapper.kt:108)
at androidx.compose.ui.node.OuterMeasurablePlaceable$remeasure$2.invoke(OuterMeasurablePlaceable.kt:95)
at androidx.compose.ui.node.OuterMeasurablePlaceable$remeasure$2.invoke(OuterMeasurablePlaceable.kt:94)
at androidx.compose.runtime.snapshots.Snapshot$Companion.observe(Snapshot.kt:1787)
at androidx.compose.runtime.snapshots.SnapshotStateObserver.observeReads(SnapshotStateObserver.kt:116)
at androidx.compose.ui.node.OwnerSnapshotObserver.observeReads$ui_debug(OwnerSnapshotObserver.kt:75)
at androidx.compose.ui.node.OwnerSnapshotObserver.observeMeasureSnapshotReads$ui_debug(OwnerSnapshotObserver.kt:63)
at androidx.compose.ui.node.OuterMeasurablePlaceable.remeasure-BRTryo0(OuterMeasurablePlaceable.kt:94)
at androidx.compose.ui.node.LayoutNode.remeasure-BRTryo0$ui_debug(LayoutNode.kt:1179)
at androidx.compose.ui.node.MeasureAndLayoutDelegate.doRemeasure-0kLqBqw(MeasureAndLayoutDelegate.kt:170)
at androidx.compose.ui.node.MeasureAndLayoutDelegate.access$doRemeasure-0kLqBqw(MeasureAndLayoutDelegate.kt:39)
at androidx.compose.ui.node.MeasureAndLayoutDelegate.measureAndLayout(MeasureAndLayoutDelegate.kt:212)
at androidx.compose.ui.platform.AndroidComposeView.onMeasure(AndroidComposeView.android.kt:543)
at android.view.View.measure(View.java:25466)
at androidx.compose.ui.platform.AbstractComposeView.onMeasure(ComposeView.android.kt:249)
at android.view.View.measure(View.java:25466)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6957)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at androidx.appcompat.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:145)
at android.view.View.measure(View.java:25466)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6957)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1552)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:842)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:721)
at android.view.View.measure(View.java:25466)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6957)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.view.View.measure(View.java:25466)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6957)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1552)
E/AndroidRuntime: at android.widget.LinearLayout.measureVertical(LinearLayout.java:842)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:721)
at android.view.View.measure(View.java:25466)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6957)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at com.android.internal.policy.DecorView.onMeasure(DecorView.java:747)
at android.view.View.measure(View.java:25466)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:3397)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:2228)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2486)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1952)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8171)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:972)
at android.view.Choreographer.doCallbacks(Choreographer.java:796)
at android.view.Choreographer.doFrame(Choreographer.java:731)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:957)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
I/Process: Sending signal. PID: 17270 SIG:
I ran into a similar issue where a #Composable annotated expected function was not visible at runtime in a different Gradle module. Hence the java.lang.NoSuchMethodError exception. The solution was to make the expected function internal and have a public wrapper function delegate to that internal function.
Crashes:
#Composable
expect fun Image() { ... }
Does not crash:
#Composable
internal expect fun InternalImage() { ... }
#Composable
fun Image() {
InternalImage()
}
This question already has answers here:
Set Margin on RecyclerView programmatically
(5 answers)
ClassCastException of LayoutParams to MarginLayoutParams after setting a view's width
(2 answers)
Closed 3 years ago.
I have a fragment, that when added via XML, as
<fragment
class="my.fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:tag="config" />
it is successfully added to the view, and i can interact with it.
However, when i try to add it programmatically, in a scrollview, as a second child as:
val layout = FrameLayout(this)
val params = FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT)
layout.layoutParams = params
layout.id = View.generateViewId()
scrollview_container.addView(layout, params)
val f2 = MyFragment.newInstance(Gson().toJson(asset))
val trans = supportFragmentManager.beginTransaction()
trans.add(layout.id, f2, "config")
trans.addToBackStack(null)
trans.commit()
i get the following error (sorry, it's long)
E/AndroidRuntime: FATAL EXCEPTION: main
Process: my.process, PID: 4950
java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.view.ViewGroup$MarginLayoutParams
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6819)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.view.View.measure(View.java:24530)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6828)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1552)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:842)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:721)
at android.view.View.measure(View.java:24530)
at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:1414)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.widget.ScrollView.onMeasure(ScrollView.java:452)
at android.view.View.measure(View.java:24530)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:735)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:481)
at android.view.View.measure(View.java:24530)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6828)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at androidx.appcompat.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:143)
at android.view.View.measure(View.java:24530)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6828)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1552)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:842)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:721)
at android.view.View.measure(View.java:24530)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6828)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.view.View.measure(View.java:24530)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6828)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1552)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:842)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:721)
at android.view.View.measure(View.java:24530)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6828)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at com.android.internal.policy.DecorView.onMeasure(DecorView.java:742)
at android.view.View.measure(View.java:24530)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:3006)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1833)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2122)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1721)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7598)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:966)
at android.view.Choreographer.doCallbacks(Choreographer.java:790)
at android.view.Choreographer.doFrame(Choreographer.java:725)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:951)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
There is no application code in this stack trace, only Android SDK calls. I have also tried to add my fragment in a NavHostFragment, but i still get the same error.
Any ideas?
Thanks in advance!
Try to change below line in your code:
val params = FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT)
To:
val params = ScrollView.LayoutParams(ScrollView.LayoutParams.MATCH_PARENT, ScrollView.LayoutParams.MATCH_PARENT);
It seems your Fragment already have Layout Params.Except to change them you should modify existing params like this.
ViewGroup.LayoutParams params = yourfragment.getView().getLayoutParams();
params.width = ViewGroup.LayoutParams.MATCH_PARENT;
params.height = ViewGroup.LayoutParams.MATCH_PARENT;
contactsFragment.getView().requestLayout();
The answer is in java language but you will get concept from here.
Error :
In total, there are three fragments.
The error occurs after going from my third fragment to my first fragment. When going from the second fragment to the fist fragment, my app does not crash.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.direct.indianpeople, PID: 20204
java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter selectedItemView
at com.example.senthil.kotlin_tablayout.Fragment.nameFrag$onViewCreated$1.onItemSelected(Unknown Source:2)
at android.widget.AdapterView.fireOnSelected(AdapterView.java:944)
at android.widget.AdapterView.dispatchOnItemSelected(AdapterView.java:933)
at android.widget.AdapterView.selectionChanged(AdapterView.java:922)
at android.widget.AdapterView.checkSelectionChanged(AdapterView.java:1105)
at android.widget.AdapterView.handleDataChanged(AdapterView.java:1081)
at android.widget.AbsSpinner.onMeasure(AbsSpinner.java:191)
at android.widget.Spinner.onMeasure(Spinner.java:602)
at androidx.appcompat.widget.AppCompatSpinner.onMeasure(AppCompatSpinner.java:428)
at android.view.View.measure(View.java:23355)
at androidx.constraintlayout.widget.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:1227)
at androidx.constraintlayout.widget.ConstraintLayout.onMeasure(ConstraintLayout.java:1572)
at android.view.View.measure(View.java:23355)
at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:1326)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.widget.ScrollView.onMeasure(ScrollView.java:355)
at android.view.View.measure(View.java:23355)
at androidx.viewpager.widget.ViewPager.onMeasure(ViewPager.java:1638)
at android.view.View.measure(View.java:23355)
at androidx.constraintlayout.widget.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:1227)
at androidx.constraintlayout.widget.ConstraintLayout.onMeasure(ConstraintLayout.java:1572)
at android.view.View.measure(View.java:23355)
at androidx.constraintlayout.widget.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:1227)
at androidx.constraintlayout.widget.ConstraintLayout.onMeasure(ConstraintLayout.java:1572)
at android.view.View.measure(View.java:23355)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6758)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at androidx.appcompat.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:143)
at android.view.View.measure(View.java:23355)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6758)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1535)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:825)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:704)
at android.view.View.measure(View.java:23355)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6758)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.view.View.measure(View.java:23355)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6758)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1535)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:825)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:704)
at android.view.View.measure(View.java:23355)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6758)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at com.android.internal.policy.DecorView.onMeasure(DecorView.java:717)
at android.view.View.measure(View.java:23355)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2919)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1749)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2042)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1637)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7797)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1172)
at android.view.Choreographer.doCallbacks(Choreographer.java:984)
at android.view.Choreographer.doFrame(Choreographer.java:809)
E/AndroidRuntime: at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1158)
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:6898)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.direct.indianpeople, PID: 20204
java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter selectedItemView
at com.example.senthil.kotlin_tablayout.Fragment.nameFrag$onViewCreated$1.onItemSelected(Unknown Source:2)
at android.widget.AdapterView.fireOnSelected(AdapterView.java:944)
at android.widget.AdapterView.dispatchOnItemSelected(AdapterView.java:933)
at android.widget.AdapterView.selectionChanged(AdapterView.java:922)
at android.widget.AdapterView.checkSelectionChanged(AdapterView.java:1105)
at android.widget.AdapterView.handleDataChanged(AdapterView.java:1081)
at android.widget.AbsSpinner.onMeasure(AbsSpinner.java:191)
at android.widget.Spinner.onMeasure(Spinner.java:602)
at androidx.appcompat.widget.AppCompatSpinner.onMeasure(AppCompatSpinner.java:428)
at android.view.View.measure(View.java:23355)
at androidx.constraintlayout.widget.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:1227)
at androidx.constraintlayout.widget.ConstraintLayout.onMeasure(ConstraintLayout.java:1572)
at android.view.View.measure(View.java:23355)
at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:1326)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.widget.ScrollView.onMeasure(ScrollView.java:355)
at android.view.View.measure(View.java:23355)
at androidx.viewpager.widget.ViewPager.onMeasure(ViewPager.java:1638)
at android.view.View.measure(View.java:23355)
at androidx.constraintlayout.widget.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:1227)
at androidx.constraintlayout.widget.ConstraintLayout.onMeasure(ConstraintLayout.java:1572)
at android.view.View.measure(View.java:23355)
at androidx.constraintlayout.widget.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:1227)
at androidx.constraintlayout.widget.ConstraintLayout.onMeasure(ConstraintLayout.java:1572)
at android.view.View.measure(View.java:23355)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6758)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at androidx.appcompat.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:143)
at android.view.View.measure(View.java:23355)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6758)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1535)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:825)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:704)
at android.view.View.measure(View.java:23355)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6758)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.view.View.measure(View.java:23355)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6758)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1535)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:825)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:704)
at android.view.View.measure(View.java:23355)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6758)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at com.android.internal.policy.DecorView.onMeasure(DecorView.java:717)
at android.view.View.measure(View.java:23355)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2919)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1749)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2042)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1637)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7797)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1172)
at android.view.Choreographer.doCallbacks(Choreographer.java:984)
at android.view.Choreographer.doFrame(Choreographer.java:809)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1158)
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:6898)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Code :
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
for (state in 0..user.StateName_.size-1){
state_name.add(user.StateName_[state])
state_id.add(user.StateId_[state])
}
spinnerTemp.adapter = ArrayAdapter(this.context!!, android.R.layout.simple_spinner_dropdown_item,state_name)
spinnerTemp.setOnItemSelectedListener(object : OnItemSelectedListener {
override fun onItemSelected(parentView: AdapterView<*>?, selectedItemView: View, position: Int, id: Long){
city_name.clear()
city_state_id.clear()
city_id.clear()
for (state in 0..user.CityName_.size - 1) {
city_state_id.add(user.CityStateId_[state])
if (state_id[position] == city_state_id[state]) {
city_name.add(user.CityName_[state])
city_id.add(user.CityId_[state])
}
}
spinnerTemp2.adapter = ArrayAdapter(
this#nameFrag.context!!,
android.R.layout.simple_spinner_dropdown_item,
city_name
)
}
override fun onNothingSelected(parentView: AdapterView<*>?) {
Toast.makeText(this#nameFrag.context,"${city_id}",Toast.LENGTH_SHORT).show()
}
})
spinnerTemp2.setOnItemSelectedListener(object : OnItemSelectedListener {
override fun onItemSelected(parentView: AdapterView<*>?, selectedItemView: View, position: Int, id: Long){
}
override fun onNothingSelected(parentView: AdapterView<*>?) {
}
} )
get_name.addTextChangedListener(object : TextWatcher {
override fun afterTextChanged(s: Editable) {}
override fun beforeTextChanged(s: CharSequence, start: Int,
count: Int, after: Int) {
}
override fun onTextChanged(s: CharSequence, start: Int,
before: Int, count: Int) {
if(check_pass(s.toString()) == true){
button14.setOnClickListener {
val intent = Intent(this#nameFrag.context, Profile2::class.java)
startActivity(intent)
}
}
else if(check_pass(s.toString()) == false)
button14.setOnClickListener{
Toast.makeText(activity?.applicationContext,"No User Found", Toast.LENGTH_LONG).show()
}
}
})
}
Its a fun bit of code that I just wrote, and I am new to android or programming in general, so I cannot figure out what's wrong.
Any help is appreciated.
I don't know what's causing it.
Try using "selectedItemView: View?" instead of "selectedItemView: View" in your arguments in onItemSelected callbacks and see what happens. The methods expect selectedItemView to have nullable type.
So I'm getting this error only when I'm running the APK and app crashes immediately. (no matter signed, unsigned release mode or debug)
but when I run the app from android studio, everything's fine.
I have both kotlin and java files in the project.
and the error is caused by a kotlin file by the way.
any idea ?
here's the error log:
java.lang.IllegalAccessError: com.app.myapp.fragment.HomeFragment$onViewCreated$1
at com.app.myapp.fragment.HomeFragment.onViewCreated(HomeFragment.kt:155)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1430)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1740)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1809)
at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:799)
at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2580)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2367)
at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2322)
at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:2199)
at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:651)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:145)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1236)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1084)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1614)
at android.view.View.measure(View.java:20221)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:716)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:462)
at android.view.View.measure(View.java:20221)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1630)
at android.view.View.measure(View.java:20221)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:716)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:462)
at android.view.View.measure(View.java:20221)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6333)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139)
at android.view.View.measure(View.java:20221)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6333)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:747)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:629)
at android.view.View.measure(View.java:20221)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6333)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.view.View.measure(View.java:20221)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6333)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:747)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:629)
at android.view.View.measure(View.java:20221)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6333)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:3140)
at android.view.View.measure(View.java:20221)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2687)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1640)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1932)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1528)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7530)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
at android.view.Choreographer.doCallbacks(Choreographer.java:686)
at android.view.Choreographer.doFrame(Choreographer.java:622)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMess
and here's the onViewCreated method:
override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
adapter = MyAdapter(list)
adapter!!.addOnItemClickListener { pos , Data->
...
}
}
there's an interface in recyclerView's adapter which passes data on each item Click. once again, this code works on debug mode and I used this structure a lot in other java classes.
any help would be appreciated. This thing is driving me crazy !