Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug] Java.Lang.IllegalArgumentException in CarouselView adjusting PeekAreaInsets in OnSizeAllocated using XF 5.0 #13436

Closed
AlfonChitoSalano opened this issue Jan 18, 2021 · 4 comments · Fixed by #13440
Labels
a/carouselview e/3 🕒 3 in-progress This issue has an associated pull request that may resolve it! p/Android t/bug 🐛

Comments

@AlfonChitoSalano
Copy link

Description

The stacktrace is here
{Java.Lang.IllegalArgumentException: Invalid target position at Java.Interop.JniEnvironment+InstanceMethods.CallVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0006e] in <89755ea61d9c4ae0a40ce90b872c9e2d>:0 at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0002a] in <89755ea61d9c4ae0a40ce90b872c9e2d>:0 at AndroidX.RecyclerView.Widget.RecyclerView+LayoutManager.StartSmoothScroll (AndroidX.RecyclerView.Widget.RecyclerView+SmoothScroller smoothScroller) [0x00027] in D:\a\1\s\generated\androidx.recyclerview.recyclerview\obj\Release\monoandroid90\generated\src\AndroidX.RecyclerView.Widget.RecyclerView.cs:7510 at Xamarin.Forms.Platform.Android.ScrollHelper.AnimateScrollToPosition (System.Int32 index, Xamarin.Forms.ScrollToPosition scrollToPosition) [0x00029] in D:\a\1\s\Xamarin.Forms.Platform.Android\CollectionView\ScrollHelper.cs:62 at Xamarin.Forms.Platform.Android.CarouselViewRenderer.ScrollTo (Xamarin.Forms.ScrollToRequestEventArgs args) [0x00037] in D:\a\1\s\Xamarin.Forms.Platform.Android\CollectionView\CarouselViewRenderer.cs:219 at Xamarin.Forms.Platform.Android.ItemsViewRenderer`3[TItemsView,TAdapter,TItemsViewSource].ScrollToRequested (System.Object sender, Xamarin.Forms.ScrollToRequestEventArgs args) [0x00022] in D:\a\1\s\Xamarin.Forms.Platform.Android\CollectionView\ItemsViewRenderer.cs:603 at Xamarin.Forms.ItemsView.OnScrollToRequested (Xamarin.Forms.ScrollToRequestEventArgs e) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Items\ItemsView.cs:219 at Xamarin.Forms.ItemsView.ScrollTo (System.Int32 index, System.Int32 groupIndex, Xamarin.Forms.ScrollToPosition position, System.Boolean animate) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Items\ItemsView.cs:172 at Xamarin.Forms.Platform.Android.CarouselViewRenderer.UpdateFromCurrentItem () [0x0003c] in D:\a\1\s\Xamarin.Forms.Platform.Android\CollectionView\CarouselViewRenderer.cs:513 at Xamarin.Forms.Platform.Android.CarouselViewRenderer.OnElementPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs changedProperty) [0x00079] in D:\a\1\s\Xamarin.Forms.Platform.Android\CollectionView\CarouselViewRenderer.cs:171 at (wrapper delegate-invoke) .invoke_void_object_PropertyChangedEventArgs(object,System.ComponentModel.PropertyChangedEventArgs) at Xamarin.Forms.BindableObject.OnPropertyChanged (System.String propertyName) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:266 at Xamarin.Forms.Element.OnPropertyChanged (System.String propertyName) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Element.cs:362 at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent) [0x00114] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:510 at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x00173] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:446 at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:383 at Xamarin.Forms.Element.SetValueFromRenderer (Xamarin.Forms.BindableProperty property, System.Object value) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Element.cs:248 at Xamarin.Forms.Platform.Android.CarouselViewRenderer.UpdateAdapter () [0x00027] in D:\a\1\s\Xamarin.Forms.Platform.Android\CollectionView\CarouselViewRenderer.cs:131 at Xamarin.Forms.Platform.Android.CarouselViewRenderer.UpdatePeekAreaInsets () [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.Android\CollectionView\CarouselViewRenderer.cs:251 at Xamarin.Forms.Platform.Android.CarouselViewRenderer.OnElementPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs changedProperty) [0x00015] in D:\a\1\s\Xamarin.Forms.Platform.Android\CollectionView\CarouselViewRenderer.cs:161 at (wrapper delegate-invoke) .invoke_void_object_PropertyChangedEventArgs(object,System.ComponentModel.PropertyChangedEventArgs) at Xamarin.Forms.BindableObject.OnPropertyChanged (System.String propertyName) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:266 at Xamarin.Forms.Element.OnPropertyChanged (System.String propertyName) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Element.cs:362 at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent) [0x00114] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:510 at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x00173] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:446 at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value, System.Boolean fromStyle, System.Boolean checkAccess) [0x0004d] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:374 at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:349 at Xamarin.Forms.CarouselView.set_PeekAreaInsets (Xamarin.Forms.Thickness value) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Items\CarouselView.cs:34 at CarouselViewIssue.MainPage.OnSizeAllocated (System.Double width, System.Double height) [0x00030] in C:\Users\User\Downloads\New folder\CarouselViewIssue.Simplified\CarouselViewIssue\MainPage.xaml.cs:55 at Xamarin.Forms.VisualElement.SizeAllocated (System.Double width, System.Double height) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:872 at Xamarin.Forms.VisualElement.SetSize (System.Double width, System.Double height) [0x00021] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:1104 at Xamarin.Forms.VisualElement.set_Bounds (Xamarin.Forms.Rectangle value) [0x0005d] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:411 at Xamarin.Forms.VisualElement.Layout (Xamarin.Forms.Rectangle bounds) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:781 at Xamarin.Forms.Platform.Android.AppCompat.Platform.LayoutRootPage (Xamarin.Forms.Page page, System.Int32 width, System.Int32 height) [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.Android\AppCompat\Platform.cs:405 at Xamarin.Forms.Platform.Android.AppCompat.Platform.Xamarin.Forms.Platform.Android.IPlatformLayout.OnLayout (System.Boolean changed, System.Int32 l, System.Int32 t, System.Int32 r, System.Int32 b) [0x0000c] in D:\a\1\s\Xamarin.Forms.Platform.Android\AppCompat\Platform.cs:232 at Xamarin.Forms.Platform.Android.PlatformRenderer.OnLayout (System.Boolean changed, System.Int32 l, System.Int32 t, System.Int32 r, System.Int32 b) [0x0001a] in D:\a\1\s\Xamarin.Forms.Platform.Android\PlatformRenderer.cs:75 at Android.Views.ViewGroup.n_OnLayout_ZIIII (System.IntPtr jnienv, System.IntPtr native__this, System.Boolean changed, System.Int32 l, System.Int32 t, System.Int32 r, System.Int32 b) [0x00008] in :0 at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.27(intptr,intptr,bool,int,int,int,int) --- End of managed Java.Lang.IllegalArgumentException stack trace ---java.lang.IllegalArgumentException: Invalid target position at androidx.recyclerview.widget.RecyclerView$SmoothScroller.start(RecyclerView.java:11807) at androidx.recyclerview.widget.RecyclerView$LayoutManager.startSmoothScroll(RecyclerView.java:8470) at crc643f46942d9dd1fff9.PlatformRenderer.n_onLayout(Native Method) at crc643f46942d9dd1fff9.PlatformRenderer.onLayout(PlatformRenderer.java:63) at android.view.View.layout(View.java:20672) at android.view.ViewGroup.layout(ViewGroup.java:6194) at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083) at android.view.View.layout(View.java:20672) at android.view.ViewGroup.layout(ViewGroup.java:6194) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323) at android.widget.FrameLayout.onLayout(FrameLayout.java:261) at android.view.View.layout(View.java:20672) at android.view.ViewGroup.layout(ViewGroup.java:6194) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323) at android.widget.FrameLayout.onLayout(FrameLayout.java:261) at android.view.View.layout(View.java:20672) at android.view.ViewGroup.layout(ViewGroup.java:6194) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323) at android.widget.FrameLayout.onLayout(FrameLayout.java:261) at android.view.View.layout(View.java:20672) at android.view.ViewGroup.layout(ViewGroup.java:6194) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656) at android.widget.LinearLayout.onLayout(LinearLayout.java:1565) at android.view.View.layout(View.java:20672) at android.view.ViewGroup.layout(ViewGroup.java:6194) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323) at android.widget.FrameLayout.onLayout(FrameLayout.java:261) at com.android.internal.policy.DecorView.onLayout(DecorView.java:753) at android.view.View.layout(View.java:20672) at android.view.ViewGroup.layout(ViewGroup.java:6194) at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2792) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2319) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1460) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7183) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:949) at android.view.Choreographer.doCallbacks(Choreographer.java:761) at android.view.Choreographer.doFrame(Choreographer.java:696) 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:6669) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)}

Steps to Reproduce

  1. Create a carouselview
  2. Set the carouselview PeekAreaInsets inside the OnSizeAllocated method
  3. Exception will be thrown

Expected Behavior

There will be no exception

Actual Behavior

Exception was thrown

Basic Information

  • Version with issue: XF 5.0
  • Last known good version: XF before 5.0

Environment

Android Only

Screenshots

image

Reproduction Link

I have uploaded a reproducible project error here https://drive.google.com/file/d/1xdrbPYqFLvysNozkqCNrNz_VL6YRLBPx/view?usp=sharing

Workaround

NA

@AlfonChitoSalano AlfonChitoSalano added s/unverified New report that has yet to be verified t/bug 🐛 labels Jan 18, 2021
@AlfonChitoSalano AlfonChitoSalano changed the title [Bug] Java.Lang.IllegalArgumentException in CarouselView adjusting PeekAreaInsets in OnSizeAllocated [Bug] Java.Lang.IllegalArgumentException in CarouselView adjusting PeekAreaInsets in OnSizeAllocated using XF 5.0 Jan 18, 2021
@samhouts samhouts added this to New in Triage Jan 18, 2021
@jsuarezruiz jsuarezruiz moved this from New to Ready For Work in Triage Jan 18, 2021
@jsuarezruiz jsuarezruiz removed the s/unverified New report that has yet to be verified label Jan 18, 2021
@jsuarezruiz jsuarezruiz added this to Backlog in CarouselView via automation Jan 18, 2021
@jsuarezruiz jsuarezruiz added the in-progress This issue has an associated pull request that may resolve it! label Jan 18, 2021
@jsuarezruiz jsuarezruiz moved this from Backlog to In Progress in CarouselView Jan 18, 2021
Triage automation moved this from Ready For Work to Closed Jan 19, 2021
CarouselView automation moved this from In Progress to Done Jan 19, 2021
rmarinho pushed a commit that referenced this issue Jan 19, 2021
…ocated (#13440) fixes #13436

* Added repro sample

* Added UITest
@AlfonChitoSalano
Copy link
Author

@rmarinho and @samhouts I have tried to update the XF version to this one https://docs.microsoft.com/en-us/xamarin/xamarin-forms/release-notes/5.0/5.0.0-sr1 with the said fix #13182 and I'm still seeing the issue. I have updated the reproducible project here https://drive.google.com/file/d/1hg9fuqDpo0LRGn7ifj4mkJ68feK64nwv/view?usp=sharing. Would you be able to reopen the issue until this is fixed. Thank you. :)

@Huaba93
Copy link

Huaba93 commented Jan 25, 2021

I agree, it still happens with Forms 5.0.0.1905. It seems to be a timing issue. When PeekArea is set after ItemsSource it crashes.
In my case, I use bindings and sometimes it happens, sometimes not.

Tested on a Samsung Galaxy s10, android 10.

@jsuarezruiz is it possible that OnAppearing gets called after OnSizeAllocated? If so, then I would adjust the test. If not, then the problem might be device or Android version specific?

This is working:

        public MainPage()
        {
            InitializeComponent();
            Task.Run(async () =>
            {
                await Task.Delay(2000);
                Device.BeginInvokeOnMainThread(() =>
                {
                    carouselView.ItemsSource = new List<DataModel>
                    {
                        new DataModel
                        {
                            Name = "N1",
                            Desc = "D1",
                            Color = Color.Yellow
                        },
                        new DataModel
                        {
                            Name = "N2",
                            Desc = "D2",
                            Color = Color.Orange
                        },
                        new DataModel
                        {
                            Name = "N3",
                            Desc = "D3",
                            Color = Color.AliceBlue
                        }
                    };
                });        
            });
        }

this is not working:

        public MainPage()
        {
            InitializeComponent();
            carouselView.ItemsSource = new List<DataModel>
            {
                new DataModel
                {
                    Name = "N1",
                    Desc = "D1",
                    Color = Color.Yellow
                },
                new DataModel
                {
                    Name = "N2",
                    Desc = "D2",
                    Color = Color.Orange
                },
                new DataModel
                {
                    Name = "N3",
                    Desc = "D3",
                    Color = Color.AliceBlue
                }
            };
        }

@chetanshingala
Copy link

Facing same issue, but not first time when it loaded. I am getting exception when I am trying to add new item to carouselView ItemsSource list. I have update the XF version to latest one Xamarin.Forms 5.0.0.1931 but still getting same exception. I am getting crash in android only in ios it is working fine.
Here is the demo in which I am getting crash: https://drive.google.com/file/d/1FWS2KkZ7-B-YD_IAc5Am1inDNBNl6fvz/view?usp=sharing. so please reopen the issue. Thanks you :)

@thisisthekap
Copy link
Contributor

@samhouts Please reopen!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a/carouselview e/3 🕒 3 in-progress This issue has an associated pull request that may resolve it! p/Android t/bug 🐛
Projects
CarouselView
  
Done
Triage
  
Closed
Development

Successfully merging a pull request may close this issue.

5 participants