Home > Net >  Any idea what could be causing this java.util.concurrentModificationException from unmanaged code in
Any idea what could be causing this java.util.concurrentModificationException from unmanaged code in

Time:10-21

I keep getting the following exception randomly from the Android project in my Xamarin.Forms application.

java.util.ConcurrentModificationException: 
  at java.util.ArrayList$Itr.next (ArrayList.java:860)
  at com.telerik.widget.primitives.panels.RadScrollView.notifyLaidOutListeners (RadScrollView.java:153)
  at com.telerik.widget.primitives.panels.RadScrollView.onLayout (RadScrollView.java:2092)
  at android.view.View.layout (View.java:24475)
  at android.view.ViewGroup.layout (ViewGroup.java:7383)
  at crc643f46942d9dd1fff9.ViewRenderer_2.n_onLayout (Native Method)
  at crc643f46942d9dd1fff9.ViewRenderer_2.onLayout (ViewRenderer_2.java:47)
  at android.view.View.layout (View.java:24475)
  at android.view.ViewGroup.layout (ViewGroup.java:7383)
  at com.xamarin.forms.platform.android.FormsViewGroup.measureAndLayout (FormsViewGroup.java:37)
  at crc643f46942d9dd1fff9.Platform_DefaultRenderer.n_onLayout (Native Method)
  at crc643f46942d9dd1fff9.Platform_DefaultRenderer.onLayout (Platform_DefaultRenderer.java:72)
  at android.view.View.layout (View.java:24475)
  at android.view.ViewGroup.layout (ViewGroup.java:7383)
  at com.xamarin.forms.platform.android.FormsViewGroup.measureAndLayout (FormsViewGroup.java:37)
  at crc643f46942d9dd1fff9.Platform_DefaultRenderer.n_onLayout (Native Method)
  at crc643f46942d9dd1fff9.Platform_DefaultRenderer.onLayout (Platform_DefaultRenderer.java:72)
  at android.view.View.layout (View.java:24475)
  at android.view.ViewGroup.layout (ViewGroup.java:7383)
  at com.xamarin.forms.platform.android.FormsViewGroup.measureAndLayout (FormsViewGroup.java:37)
  at crc643f46942d9dd1fff9.Platform_DefaultRenderer.n_onLayout (Native Method)
  at crc643f46942d9dd1fff9.Platform_DefaultRenderer.onLayout (Platform_DefaultRenderer.java:72)
  at android.view.View.layout (View.java:24475)
  at android.view.ViewGroup.layout (ViewGroup.java:7383)
  at com.xamarin.forms.platform.android.FormsViewGroup.measureAndLayout (FormsViewGroup.java:37)
  at crc64ee486da937c010f4.FrameRenderer.n_onLayout (Native Method)
  at crc64ee486da937c010f4.FrameRenderer.onLayout (FrameRenderer.java:47)
  at android.view.View.layout (View.java:24475)
  at android.view.ViewGroup.layout (ViewGroup.java:7383)
  at crc643f46942d9dd1fff9.Platform_DefaultRenderer.n_onLayout (Native Method)
  at crc643f46942d9dd1fff9.Platform_DefaultRenderer.onLayout (Platform_DefaultRenderer.java:72)
  at android.view.View.layout (View.java:24475)
  at android.view.ViewGroup.layout (ViewGroup.java:7383)
  at com.xamarin.forms.platform.android.FormsViewGroup.measureAndLayout (FormsViewGroup.java:37)
  at crc643f46942d9dd1fff9.Platform_DefaultRenderer.n_onLayout (Native Method)
  at crc643f46942d9dd1fff9.Platform_DefaultRenderer.onLayout (Platform_DefaultRenderer.java:72)
  at android.view.View.layout (View.java:24475)
  at android.view.ViewGroup.layout (ViewGroup.java:7383)
  at com.xamarin.forms.platform.android.FormsViewGroup.measureAndLayout (FormsViewGroup.java:37)
  at crc643f46942d9dd1fff9.ScrollViewContainer.n_onLayout (Native Method)
  at crc643f46942d9dd1fff9.ScrollViewContainer.onLayout (ScrollViewContainer.java:46)
  at android.view.View.layout (View.java:24475)
  at android.view.ViewGroup.layout (ViewGroup.java:7383)
  at android.widget.FrameLayout.layoutChildren (FrameLayout.java:332)
  at android.widget.FrameLayout.onLayout (FrameLayout.java:270)
  at androidx.core.widget.NestedScrollView.onLayout (NestedScrollView.java:1854)
  at crc643f46942d9dd1fff9.ScrollViewRenderer.n_onLayout (Native Method)
  at crc643f46942d9dd1fff9.ScrollViewRenderer.onLayout (ScrollViewRenderer.java:91)
  at android.view.View.layout (View.java:24475)
  at android.view.ViewGroup.layout (ViewGroup.java:7383)
  at crc643f46942d9dd1fff9.Platform_DefaultRenderer.n_onLayout (Native Method)
  at crc643f46942d9dd1fff9.Platform_DefaultRenderer.onLayout (Platform_DefaultRenderer.java:72)
  at android.view.View.layout (View.java:24475)
  at android.view.ViewGroup.layout (ViewGroup.java:7383)
  at com.xamarin.forms.platform.android.FormsViewGroup.measureAndLayout (FormsViewGroup.java:37)
  at crc643f46942d9dd1fff9.PageRenderer.n_onLayout (Native Method)
  at crc643f46942d9dd1fff9.PageRenderer.onLayout (PageRenderer.java:72)
  at android.view.View.layout (View.java:24475)
  at android.view.ViewGroup.layout (ViewGroup.java:7383)
  at com.xamarin.forms.platform.android.FormsViewGroup.measureAndLayout (FormsViewGroup.java:37)
  at crc64720bb2db43a66fe9.NavigationPageRenderer.n_onLayout (Native Method)
  at crc64720bb2db43a66fe9.NavigationPageRenderer.onLayout (NavigationPageRenderer.java:65)
  at android.view.View.layout (View.java:24475)
  at android.view.ViewGroup.layout (ViewGroup.java:7383)
  at com.xamarin.forms.platform.android.FormsViewGroup.measureAndLayout (FormsViewGroup.java:37)
  at crc64720bb2db43a66fe9.MasterDetailContainer.n_onLayout (Native Method)
  at crc64720bb2db43a66fe9.MasterDetailContainer.onLayout (MasterDetailContainer.java:46)
  at android.view.View.layout (View.java:24475)
  at android.view.ViewGroup.layout (ViewGroup.java:7383)
  at androidx.drawerlayout.widget.DrawerLayout.onLayout (DrawerLayout.java:1231)
  at crc64720bb2db43a66fe9.MasterDetailPageRenderer.n_onLayout (Native Method)
  at crc64720bb2db43a66fe9.MasterDetailPageRenderer.onLayout (MasterDetailPageRenderer.java:68)
  at android.view.View.layout (View.java:24475)
  at android.view.ViewGroup.layout (ViewGroup.java:7383)
  at crc643f46942d9dd1fff9.PlatformRenderer.n_onLayout (Native Method)
  at crc643f46942d9dd1fff9.PlatformRenderer.onLayout (PlatformRenderer.java:55)
  at android.view.View.layout (View.java:24475)
  at android.view.ViewGroup.layout (ViewGroup.java:7383)
  at android.widget.RelativeLayout.onLayout (RelativeLayout.java:1103)
  at android.view.View.layout (View.java:24475)
  at android.view.ViewGroup.layout (ViewGroup.java:7383)
  at android.widget.FrameLayout.layoutChildren (FrameLayout.java:332)
  at android.widget.FrameLayout.onLayout (FrameLayout.java:270)
  at android.view.View.layout (View.java:24475)
  at android.view.ViewGroup.layout (ViewGroup.java:7383)
  at android.widget.FrameLayout.layoutChildren (FrameLayout.java:332)
  at android.widget.FrameLayout.onLayout (FrameLayout.java:270)
  at android.view.View.layout (View.java:24475)
  at android.view.ViewGroup.layout (ViewGroup.java:7383)
  at android.widget.FrameLayout.layoutChildren (FrameLayout.java:332)
  at android.widget.FrameLayout.onLayout (FrameLayout.java:270)
  at android.view.View.layout (View.java:24475)
  at android.view.ViewGroup.layout (ViewGroup.java:7383)
  at android.widget.LinearLayout.setChildFrame (LinearLayout.java:1829)
  at android.widget.LinearLayout.layoutVertical (LinearLayout.java:1673)
  at android.widget.LinearLayout.onLayout (LinearLayout.java:1582)
  at android.view.View.layout (View.java:24475)
  at android.view.ViewGroup.layout (ViewGroup.java:7383)
  at android.widget.FrameLayout.layoutChildren (FrameLayout.java:332)
  at android.widget.FrameLayout.onLayout (FrameLayout.java:270)
  at com.android.internal.policy.DecorView.onLayout (DecorView.java:1225)
  at android.view.View.layout (View.java:24475)
  at android.view.ViewGroup.layout (ViewGroup.java:7383)
  at android.view.ViewRootImpl.performLayout (ViewRootImpl.java:4260)
  at android.view.ViewRootImpl.performTraversals (ViewRootImpl.java:3695)
  at android.view.ViewRootImpl.doTraversal (ViewRootImpl.java:2618)
  at android.view.ViewRootImpl$TraversalRunnable.run (ViewRootImpl.java:9971)
  at android.view.Choreographer$CallbackRecord.run (Choreographer.java:1010)
  at android.view.Choreographer.doCallbacks (Choreographer.java:809)
  at android.view.Choreographer.doFrame (Choreographer.java:744)
  at android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:995)
  at android.os.Handler.handleCallback (Handler.java:938)
  at android.os.Handler.dispatchMessage (Handler.java:99)
  at android.os.Looper.loop (Looper.java:246)
  at android.app.ActivityThread.main (ActivityThread.java:8538)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:602)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1130)

It seems to be happening randomly and I am just hoping that someone has faced the same issue and has an idea on what to do? I am unable to debug as it comes from code that is unmanaged. Any thoughts on what could be causing this and any potential solutions would be much apppreciated.

Thanks

CodePudding user response:

Since you only provide error information, from the error information, this error generally appears in the iteration of ArrayList.

The main reason is that the values of modCount and expectedModCount are inconsistent due to calling list.remove() method.

If you use an iterator This error can be avoided by calling Iterator.remove() directly.

If you just call the API without other operations, it should be a similar problem with the internal interface.

CodePudding user response:

After much debugging it turns out it was related to having a Horizontally scrollable control (Telerik DataGrid) inside a vertically scrollable Layout (Scrollview).

To fix this, in my OnAppearing() override I checked that the Device.RuntimePlatform is Android and checked if the DataGrid Control should be visible by using the IsVisible Binding property from my view model and then removed it. This control is inside a grid so I was able to do this using the x:Names of the controls and calling .Children.Remove().

so the code looked something like:

var vm = BindingContext as MyViewModelName;
if (Device.RuntimePlatform == Device.Android && !vm.DataGridIsVisible){
    MyGridControl.Children.Remove(MyDataGridControl);
}

Note that MyGridControl and MyDataGridControl here are the X:Name properties of the controls.

  • Related