【发布时间】:2018-03-21 06:57:50
【问题描述】:
您好,我正在尝试读取表中名字为“John”的用户。
async private void GetUsers()
{
Initialize();
SyncCoffee();
try
{
await coffeeTable.PullAsync("user", coffeeTable.Where(ct => ct.FirstName == "John" ));
}
catch (Exception er)
{
await DisplayAlert("Alert", "the error: "+er, "ok");
}
}
初始化方法
public async Task Initialize()
{
var mainPage = new MainPage();
if (isInitialised)
{
return;
}
MobileServiceClient client = new MobileServiceClient("database link");
const string path = "syncstore.db";
var store = new MobileServiceSQLiteStore(path);
store.DefineTable<User>();
await MobileService.SyncContext.InitializeAsync(store, new MobileServiceSyncHandler());
coffeeTable = MobileService.GetSyncTable<User>();
isInitialised = true;
}
同步方法
public async Task SyncCoffee()
{
try
{
await coffeeTable.PullAsync("allusers", coffeeTable.CreateQuery());
await MobileService.SyncContext.PushAsync();
}
catch (Exception ex)
{
Debug.WriteLine("Unable to sync coffees, that is alright as we have offline capabilities: " + ex);
}
}
我不断收到的错误是
System.NullReferenceException:对象引用未设置为对象的实例。
欢迎任何帮助,因为我对此很陌生。
【问题讨论】:
-
嗨@JohnDoe - 您可以在此处提供更多信息。哪一行代码触发了空引用异常?
-
Initialize() 和 SyncCoffee() 都是异步的,但都不是使用 await 调用的。这可能会带来问题
-
@Jason andrew 询问确切的异常点,而不是函数名称
-
我是在指出 OP,没有回答 Andrew 的问题
-
@AndrewShepherd 错误似乎在线 await coffeeTable.PullAsync("user", coffeeTable.Where(ct => ct.FirstName == "John" ));
标签: azure xamarin xamarin.forms xamarin.android azure-mobile-services