xamarin构成主详细信息页面 - null异常sqlite

时间:2018-04-26 20:50:02

标签: c# xamarin xamarin.forms xamarin.ios navigation

我是Xamarin的新人。我想添加一个侧边菜单,所以我在我的项目中使用this code on GitHub并实现。

我有这个AccountView页面:

public partial class AccountsView : ContentPage
{ 
    public AccountsView()
    {
        InitializeComponent();

        GetAccountsAsync();
    }
    private async void GetAccountsAsync()
    {
        var accounts = await SQLHelper.Connection.Table<Account>().ToListAsync();

        lvwAccounts.ItemsSource = accounts;
    }

    async void Handle_Clicked(object sender, System.EventArgs e)
    {
        var account = (Account)((Button)sender).BindingContext;
        await Navigation.PushAsync(new AccountDetailsView(account.Id));
    }
} 

当我点击菜单进入此页面时,我收到异常"object reference not set to an instance of an object"和内部异常:

  

&#34; at project.Views.AccountsView + d__2.MoveNext()[0x0000f] in /Users/user/Projects/project/project/Views/AccountsView.xaml.cs:24 \ n ---来自先前位置的堆栈跟踪结束被抛出--- \ n在/Library/Frameworks/Xamarin.iOS.framework/Versions/11.9.1.24/src/Xamarin.iOS/mcs/class/中的System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()[0x0000c] referencesource / mscorlib / system / runtime / exceptionservices / exceptionservicescommon.cs:152 \ n在/ Library / Frameworks / Xamarin中的System.Runtime.CompilerServices.AsyncMethodBuilderCore +&lt;&gt; c.b__6_0(System.Object state)[0x00000]。 iOS.framework / Versions / 11.9.1.24 / src / Xamarin.iOS / mcs / class / referencesource / mscorlib / system / runtime / compilerservices / AsyncMethodBuilder.cs:1018 \ n在UIKit.UIKitSynchronizationContext + c__AnonStorey0。&lt;&gt; m__0( )@Library/Frameworks/Xamarin.iOS.framework/Versions/11.9.1.24/src/Xamarin.iOS/UIKit/UIKitSynchronizationContext.cs:24 \ n中的[0x00000]在Foundation.NSAsyncActionDispatcher.Apply()[ 0x00000]在/Library/Frameworks/Xamarin.iOS.framework/Versions/11.9.1.24/src/Xamarin.iOS/Foundation/NSAction.cs:163 \ n ---从前一个引发异常的位置的堆栈跟踪结束 - - \ n at(包装器托管到原生)UIKit.UIApplication.UIApplicationMain(int,string [],intptr,intptr)\ n在UIKit.UIApplication.Main(System.String [] args,System.IntPtr principal, System.IntPtr委托)[0x00005] / Uibit.UIApplication.Main / System /。 String [] args,System.String principalClassName,System.String delegateClassName)[0x00038] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.9.1.24/src/Xamarin.iOS/UIKit/UIApplication.cs:63 \在/Users/user/Projects/project/iOS/Main.cs:17&#34;

中的project.iOS.Application.Main(System.String [] args)[0x00001]

如果我删除GetAccountsAsync()方法并且它从ctor调用,则一切正常,但没有数据。

async调用DB会导致问题。

如果我没有实现侧面菜单和母版页,我的代码可以正常工作。

有人可以帮我这个吗?

0 个答案:

没有答案