を待って、私の見解モデルでは、私は、私のデータベースの後ろに私のコードでXamarinは、SQLiteのに問題がフォームと私はsqliteのネット-PCL nugetを使用してい
private SQLiteAsyncConnection connection;
public ObservableCollection<Announcement> AnnouncementList { get; private set; }
public AnnouncementsViewModel() {
connection = DependencyService.Get<ISQLiteDb>().GetConnection();
Initialize();
}
public async void Initialize() {
await connection.CreateTableAsync<Announcement>();
var announcements = await connection.Table<Announcement>().ToListAsync();
AnnouncementList = new ObservableCollection<Announcement>(announcements);
System.Diagnostics.Debug.WriteLine("***********************************");
System.Diagnostics.Debug.WriteLine(AnnouncementList.Count);
}
からのお知らせの一覧を取得しようとしていますコンストラクタで:
BindingContext = new AnnouncementsViewModel();
InitializeComponent();
var list = (BindingContext as AnnouncementsViewModel).AnnouncementList;
私が手にエラーがある:
System.NullReferenceException:オブジェクト参照インスタンスに設定されていませんオブジェクトの。
私はviewModelにブレークポイントを設定します。最初のコードに到着すると、コードが背後に戻り、アプリケーションがクラッシュします。 AnnouncementListがviewModelに埋め込まれておらず、星印が印刷されなかったため、null例外が発生します。 この問題を解決するにはどうすればよいですか?
おかげ
例外のコールスタックは何ですか? –
'(BindingContext as AnnouncementsViewModel)'私はこれがヌルであると確信しています – Alex
@ j0ey_wh私はこの行にブレークポイントを設定します。タイプを解決できませんでした:AnnouncementsViewModel – Mireille