J.Dhaik
J.Dhaik

Reputation: 103

Xamarin page loads but doesn't show up on screen

I have a problem with my program getting stuck at the await Pushmodalasync part. It's supposed to get stuck there until you login into the application, but the loginpage never loads, it's just stuck at the loading screen.

It's the same problem on iOS and Android.

Loading the login page

protected async override void OnAppearing()
{
    if (App.Client.Initilized == false)
    {
        await App.Client.Init();
    }

    if (App.Client.LoggedIn == false)
    {
        ShowLoginPage();
        return;
    }

    ShowIssuesFromCurrentLocation();
} 

Calling the login page

private async void ShowLoginPage()
{
    MessagingCenter.Subscribe<LoginPage>(this, "OnLoginPageClosed", (sender) =>
    {
        MessagingCenter.Unsubscribe<LoginPage>(this, "OnLoggedIn");

        if (App.Client.LoggedIn == false)
        {
            Issues.Clear();
        }
        else
        {
            ShowIssuesFromCurrentLocation();
        }
    });

    await this.Navigation.PushModalAsync(new LoginPage());
}

The loginpage itself

public partial class LoginPage : ContentPage
{
    public LoginViewModel data;
    public LoginViewModel Data { get { return data; } }
    public LoginPage()
    {
        this.data = App.Client.GetCurrentLoginModel();
        this.BindingContext = this.data;
        this.Title = "Login";
        InitializeComponent();
    }

The xaml part of the login class

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="ASFT.IssueManager.LoginPage" Padding="10">
  <ContentPage.Resources>
    <ResourceDictionary>
      <x:String x:Key="Labelfont">Medium</x:String>
      <x:String x:Key="Titlefont">Large</x:String>
    </ResourceDictionary>
  </ContentPage.Resources>
  <StackLayout Orientation="Vertical" VerticalOptions="Center" HorizontalOptions="FillAndExpand" Spacing="10" >
    <StackLayout Orientation="Vertical" VerticalOptions="Start" HorizontalOptions="Center" Spacing="10" WidthRequest="350">
      <Label Text="Login" VerticalOptions="Center" HorizontalOptions="Start" FontSize="{StaticResource Titlefont}"/>
      <BoxView HeightRequest="5" Color="Gray"/>
      <Label Text="Host" VerticalOptions="Center" HorizontalOptions="Start" FontSize="{StaticResource Labelfont}"/>
      <Entry Placeholder="Host/URL" Text="{Binding Host}" />
      <Label Text="UserName" VerticalOptions="Center" HorizontalOptions="Start" FontSize="{StaticResource Labelfont}"/>
      <Entry Placeholder="User name / Account" Text="{Binding Username}" />
      <Label Text="Password" VerticalOptions="Center" HorizontalOptions="Start" FontSize="{StaticResource Labelfont}"/>
      <Entry Placeholder="Password" IsPassword="true" Text="{Binding Password}" />
      <BoxView HeightRequest="5" Color="Gray"/>
      <Button x:Name="btnLogin" Text="Login" HorizontalOptions="FillAndExpand" Clicked="OnButtonLogin" WidthRequest="100"/>
    </StackLayout>
  </StackLayout>
</ContentPage>

InitializeComponent method

[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Forms.Build.Tasks.XamlG", "0.0.0.0")] private void InitializeComponent() { global::Xamarin.Forms.Xaml.Extensions.LoadFromXaml(this, typeof(LoginPage)); btnLogin = global::Xamarin.Forms.NameScopeExtensions.FindByName(this, "btnLogin"); }

The loginview model

public LoginViewModel GetCurrentLoginModel()
    {
      // DEBUG
      if (state.Username.Length == 0)
        state.Username = "mudemo";
      if (state.Host.Length == 0)
        state.Host = "";

      // VERY DEBUG. - REMOVE 
      //String password = "4R5zE6mw";
      String password = "mudemo";

      return new LoginViewModel
      {
        // default debug account
        Host = state.Host,
        Username = state.Username,
        Password = password
      };
    }

Error message:

I'm using xamarinsforms 2.5.0.12, the latest stable available.

12-14 12:21:15.185 D/AbsListView(22659): unregisterIRListener() is called 12-14 12:21:15.190 D/Mono (22659): DllImport searching in: '__Internal' ('(null)'). 12-14 12:21:15.190 D/Mono (22659): Searching for 'java_interop_jnienv_call_nonvirtual_float_method_a'. 12-14 12:21:15.190 D/Mono (22659): Probing 'java_interop_jnienv_call_nonvirtual_float_method_a'. 12-14 12:21:15.190 D/Mono (22659): Found as 'java_interop_jnienv_call_nonvirtual_float_method_a'. 12-14 12:21:15.220 D/Mono (22659): DllImport searching in: '__Internal' ('(null)'). 12-14 12:21:15.220 D/Mono (22659): Searching for 'java_interop_jnienv_call_void_method'. 12-14 12:21:15.225 D/Mono
(22659): Probing 'java_interop_jnienv_call_void_method'. 12-14 12:21:15.225 D/Mono (22659): Found as 'java_interop_jnienv_call_void_method'. 12-14 12:21:15.280 D/AbsListView(22659): unregisterIRListener() is called 12-14 12:21:19.350 D/Mono (22659): Unloading image System.Diagnostics.Debug.dll [0x8356da00]. 12-14 12:21:19.350 D/Mono
(22659): Image addref System.Diagnostics.Debug[0x8356ac40] -> System.Diagnostics.Debug.dll[0x7fbf0d28]: 5 12-14 12:21:19.350 D/Mono (22659): Config attempting to parse: 'System.Diagnostics.Debug.dll.config'. 12-14 12:21:19.350 D/Mono
(22659): Config attempting to parse: '/usr/local/etc/mono/assemblies/System.Diagnostics.Debug/System.Diagnostics.Debug.config'. 12-14 12:21:19.350 D/Mono (22659): Assembly Ref addref ASFT.IssueManager[0x7db3d5c0] -> System.Diagnostics.Debug[0x7fc01d28]: 3 Resolved pending breakpoint at 'LoginPage.xaml.cs:32,1' to void ASFT.IssueManager.LoginPage.OnDisappearing () [0x0000d]. Resolved pending breakpoint at 'LoginPage.xaml.cs:31,1' to void ASFT.IssueManager.LoginPage.OnDisappearing () [0x00001]. 12-14 12:21:24.365 D/Mono (22659): Image addref System.Diagnostics.Tools[0x83567040] -> System.Diagnostics.Tools.dll[0x835676b0]: 2 12-14 12:21:24.365 D/Mono (22659): Prepared to set up assembly 'System.Diagnostics.Tools' (System.Diagnostics.Tools.dll) 12-14 12:21:24.365 D/Mono (22659): Assembly System.Diagnostics.Tools[0x83567040] added to domain RootDomain, ref_count=1 12-14 12:21:24.365 D/Mono (22659): AOT: image 'System.Diagnostics.Tools.dll.so' not found: dlopen failed: library "/data/app-lib/com.asft.event-68/libaot-System.Diagnostics.Tools.dll.so" not found 12-14 12:21:24.365 D/Mono (22659): AOT: image '/usr/local/lib/mono/aot-cache/arm/System.Diagnostics.Tools.dll.so' not found: dlopen failed: library "/data/app-lib/com.asft.event-68/libaot-System.Diagnostics.Tools.dll.so" not found 12-14 12:21:24.365 D/Mono (22659): Config attempting to parse: 'System.Diagnostics.Tools.dll.config'. 12-14 12:21:24.365 D/Mono (22659): Config attempting to parse: '/usr/local/etc/mono/assemblies/System.Diagnostics.Tools/System.Diagnostics.Tools.config'. 12-14 12:21:24.365 D/Mono (22659): Assembly Ref addref ASFT.IssueManager[0x7db3d5c0] -> System.Diagnostics.Tools[0x83567040]: 2 12-14 12:21:24.365 D/Mono (22659): Assembly Ref addref System.Diagnostics.Tools[0x83567040] -> System[0x7ed17940]: 12 12-14 12:21:26.585 W/Mono (22659): The request to load the assembly mscorlib v4.0.0.0 was remapped to v2.0.5.0 12-14 12:21:26.585 D/Mono
(22659): Unloading image mscorlib.dll [0x835670b0]. 12-14 12:21:26.585 D/Mono (22659): Config attempting to parse: 'mscorlib.dll.config'. 12-14 12:21:26.585 D/Mono (22659): Config attempting to parse: '/usr/local/etc/mono/assemblies/mscorlib/mscorlib.config'. 12-14 12:21:26.585 D/Mono (22659): Unloading image System.Globalization.dll [0x83579b48]. 12-14 12:21:26.585 D/Mono
(22659): Image addref System.Globalization[0x8357a8b0] -> System.Globalization.dll[0x7f17f3d0]: 6 12-14 12:21:26.585 D/Mono
(22659): Config attempting to parse: 'System.Globalization.dll.config'. 12-14 12:21:26.585 D/Mono
(22659): Config attempting to parse: '/usr/local/etc/mono/assemblies/System.Globalization/System.Globalization.config'. 12-14 12:21:26.585 D/Mono (22659): Assembly Ref addref Xamarin.Forms.Xaml[0x7dbd5a78] -> System.Globalization[0x7f17ffd8]: 4 Loaded assembly: System.Diagnostics.Tools.dll [External] 12-14 12:21:26.600 W/Mono (22659): The request to load the assembly mscorlib v4.0.0.0 was remapped to v2.0.5.0 12-14 12:21:26.600 D/Mono
(22659): Unloading image mscorlib.dll [0x835670b0]. 12-14 12:21:26.600 D/Mono (22659): Config attempting to parse: 'mscorlib.dll.config'. 12-14 12:21:26.600 D/Mono (22659): Config attempting to parse: '/usr/local/etc/mono/assemblies/mscorlib/mscorlib.config'. 12-14 12:21:26.805 D/Mono (22659): Unloading image System.Runtime.Extensions.dll [0x8359dec8]. 12-14 12:21:26.805 D/Mono (22659): Image addref System.Runtime.Extensions[0x83595340] -> System.Runtime.Extensions.dll[0x7eb780b0]: 6 12-14 12:21:26.805 D/Mono (22659): Config attempting to parse: 'System.Runtime.Extensions.dll.config'. 12-14 12:21:26.805 D/Mono
(22659): Config attempting to parse: '/usr/local/etc/mono/assemblies/System.Runtime.Extensions/System.Runtime.Extensions.config'. 12-14 12:21:26.805 D/Mono (22659): Assembly Ref addref Xamarin.Forms.Xaml[0x7dbd5a78] -> System.Runtime.Extensions[0x7eb77b68]: 4 12-14 12:21:31.060 I/Choreographer(22659): Skipped 946 frames! The application may be doing too much work on its main thread. 12-14 12:21:31.075 D/AbsListView(22659): unregisterIRListener() is called Unhandled Exception:

System.ArgumentNullException: Value cannot be null. Parameter name: source

App start

 public App()
    {
      Client = new AppIssueClient();
      // The root page of your application
      MainPage = GetMainPage();
    }

    public async void Init()
    {
      await Client.Init();
    }

    public static Page GetMainPage()
    {
      var p = new NavigationPage(new IssuesPage(-1));
      App.Navigation = p.Navigation;
      return p;//  new NavigationPage(new HomePage());
    }

Upvotes: 0

Views: 2926

Answers (2)

EvZ
EvZ

Reputation: 12179

There are multiple possible problems spotted in your code sample:

  1. In the constructor of LoginPage InitializeComponent(); should come first.
  2. In OnAppearing() you have to await ShowLoginPage();, otherwise the code will continue the execution.
  3. The exception is pointing towards XAML, try to enable XAMLC.

Try to eliminate the problems I spotted one by one, hopefully you will find a solution.

Upvotes: 2

qubuss
qubuss

Reputation: 268

I had similar problem with load page and it was stop in launch page because I have problem with ViewModel. Can you show your LoginModel?

And try instead of this

await this.Navigation.PushModalAsync(new LoginPage());

use:

MainPage = new LoginPage();

--EDIT In Your ViewModel:

public class LoginViewModel : INotifyPropertyChanged
{
    String username;
    public String Username{
        get{
            return username;
        }set{
            username = value;
            RaisePropertyChanged("Username");
        }
    }

    String password;
    public String Password{
        get{
            return password;
        }set{
            password = value;
            RaisePropertyChanged("Password");
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;

    protected void RaisePropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}

Then in your ContentPage you use:

public partial class LoginPage : ContentPage
{
  public LoginViewModel data;
  public LoginViewModel Data { get { return data; } }
  public LoginPage()
  {
     //this.data = App.Client.GetCurrentLoginModel();
     this.BindingContext = new LoginViewModel() // or you get from App.cs
     this.Title = "Login";
     InitializeComponent();
 }

Upvotes: 0

Related Questions