Share via

Getting "Java.Lang.IllegalStateException" error with bottom navigation bar on Android device

Michael Alfred 25 Reputation points
2023-03-14T02:32:59.0433333+00:00

I have created a bottom navigation bar for my Maui app, which was working perfectly fine. However, after I created another page, I started getting the following error on my Android device: "Java.Lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first."

I have tried running the app on my Windows machine and it works perfectly fine without any errors, so I believe this issue is specific to Android devices. I have already tried looking for solutions online, but I couldn't find anything that worked for me.

Here's the code for my bottom navigation bar:

AppShell.xaml

**  

<!--This navigation works when the user starts the application-->

  <ShellContent  ContentTemplate="{DataTemplate View:MainPage}" />

       <ShellContent ContentTemplate="{DataTemplate View:Registration}"/>

    

    

    <!--When the user is logged in the bottom nav appears-->

    <TabBar Route="DeriTabBar">

        <Tab Title="Home" Icon="deri_food_logo.png">

            <ShellContent ContentTemplate="{DataTemplate View:Dashboard}" Route="Dashboard"/>

        </Tab>

        <Tab Title="Login" Icon="deri_food_logo.png">

            <ShellContent ContentTemplate="{DataTemplate View:Login}"  Route="Login"/>

        </Tab>

        <Tab Title="Restaurant" Icon="deri_food_logo.png">

            <ShellContent ContentTemplate="{DataTemplate View:Restaurant}"  Route="Restaurant"/>

        </Tab>

    </TabBar>**



Registration Viewmodel

**await Shell.Current.GoToAsync($"//DeriTabBar/{nameof(Dashboard)}?email={Email}"); ** 

and here is code that navigates to the dashboard with the email parameter


Developer technologies | .NET | .NET Multi-platform App UI
Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.


1 answer

Sort by: Most helpful
  1. Ahmed Thabet Elshamandy 40 Reputation points
    2023-10-29T08:41:29.3833333+00:00

    @Michael Alfred

    Hi Michael,

    Me too found this exception in my application . but I use await Navigation.PushAsync()
    when using pushAsync and popAsync functions . to go to another page or to go back .not used shell .

    I tried to search but not found any solution.

    Please if you found any thing help us to fix it , share it

    Thank You,

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.