Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android App crashes if CollectionView have more than one item #17735

Closed
HobDev opened this issue Sep 29, 2023 · 4 comments
Closed

Android App crashes if CollectionView have more than one item #17735

HobDev opened this issue Sep 29, 2023 · 4 comments
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView platform/android 🤖 s/needs-info Issue needs more info from the author t/bug Something isn't working

Comments

@HobDev
Copy link

HobDev commented Sep 29, 2023

Description

If the CollectionView ItemsSource have more than one item the Android app crashes.

Steps to Reproduce

Run the reproduction app and it will crash on Android because the ItemsSource ObservableCollection have 4 items. But if the three items are commented out and the app is deployed with one item the deployment is successful.

Link to public reproduction project repository

https://github.com/HobDev/DotNet8MauiBugs/tree/ButtonClickCrashIssue

Version with bug

8.0.0-rc.1.9171

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 14

Did you find any workaround?

No

Relevant log output

No response

@HobDev HobDev added the t/bug Something isn't working label Sep 29, 2023
@HobDev
Copy link
Author

HobDev commented Sep 29, 2023

The error message that I get in crash is :

Java.Lang.IllegalStateException: 'The specified child already has a parent. You must call removeView() on the child's parent first.'

The same error same as reported in this bug report.

@jsuarezruiz jsuarezruiz added platform/android 🤖 area-controls-collectionview CollectionView, CarouselView, IndicatorView labels Sep 29, 2023
@jsuarezruiz
Copy link
Contributor

You are creating the Button outside of the ItemTemplate. So, this will create a single instance and will try to reuse it in every cell. Moving the Button inside the template fixes any possible issues (only see a single item, even a possible crash because the parent already has been assigned).

@jsuarezruiz jsuarezruiz added the s/needs-info Issue needs more info from the author label Oct 6, 2023
@ghost
Copy link

ghost commented Oct 6, 2023

Hi @HobDev. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@HobDev
Copy link
Author

HobDev commented Oct 7, 2023

The issue is fixed after implementing the fix suggested by @jsuarezruiz

@HobDev HobDev closed this as completed Oct 7, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Nov 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView platform/android 🤖 s/needs-info Issue needs more info from the author t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants