我目前正在爲Azure使用windows phone 8.1開發應用程序。 (根據我的經驗,我不會真的推薦給你)。無論如何...我有其中的多個控制器類,他們真的是這樣做的(檢查數據庫中的某些東西是否已經存在,如果沒有,就創建它)。我的問題必須是在檢查數據庫,如果一個條目已經存在的read()函數:Azure MobileService空引用異常
public async void Read(Device device)
{
IMobileServiceTable mobileServiceTable = Connect();
MobileServiceCollection<Device, Device> devices = null;
try
{
devices = await mobileServiceTable.MobileServiceClient.GetTable<Device>().Where(d => d.Manufacturer == device.Manufacturer && d.Model == device.Model).ToCollectionAsync();
}
catch (Exception e)
{
if (_onDeviceControllerListener != null)
{
_onDeviceControllerListener.OnError(ControllerError.Error.ReadFromDatabase, e.ToString());
}
return;
}
if (_onDeviceControllerListener != null && devices != null)
{
_onDeviceControllerListener.OnRead(devices);
}
}
這一個完美的作品應該如何,但奧得一個這基本上只是一個副本拋出一個NullReferenceException由行「apps = await mobileServiceTab ...」:
public async void Read(Model.App app)
{
IMobileServiceTable mobileServiceTable = Connect();
MobileServiceCollection<Model.App, Model.App> apps = null;
try {
apps = await mobileServiceTable.MobileServiceClient.GetTable<Model.App>().Where(a => a.HardwareId == app.HardwareId && a.PackageId == app.PackageId).ToCollectionAsync();
}
catch (Exception e)
{
if (_onAppControllerListener != null)
{
_onAppControllerListener.OnError(ControllerError.Error.ReadFromDatabase, e.ToString());
}
return;
}
if (_onAppControllerListener != null)
{
_onAppControllerListener.OnRead(apps);
}
}
有人知道問題是什麼嗎? 感謝您的幫助
什麼是您的異常的堆棧跟蹤? – carlosfigueira 2015-02-24 17:26:56
你可以通過它來告訴我們,當錯誤被拋出時哪個對象爲空? – Chris 2015-02-24 18:51:20