我的代码崩溃并在模拟器上出现以下错误。它尝试在 GetDataFromOdataService ()方法中运行try块并抛出错误并发出警报。我正在使用Xamarin.Form
using Simple.OData.Client;
using System.Threading.Tasks;
private ODataClient mODataClient;
protected async override void OnAppearing ()
{
base.OnAppearing ();
await InitializeDataService ();
await GetDataFromOdataService();
}
public async Task <bool> InitializeDataService(){
try {
mODataClient = new ODataClient ("http://services.odata.org/Northwind/Northwind.svc/");
}
catch {
await DisplayAlert("Error", "Connection Error", "OK", "Cancel");
System.Diagnostics.Debug.WriteLine("ERROR!");
}
return true;
}
public async Task<bool> GetDataFromOdataService (){
try {
myCustomers= await mODataClient.For("Customers").Top(10).FindEntriesAsync();
}
catch {
await DisplayAlert("Error", "Connection Error", "OK", "Cancel");
System.Diagnostics.Debug.WriteLine("ERROR!");
}
return true;
}
答案 0 :(得分:1)
夫妻问题: -
在构造函数中它正在执行var list = new ListView()
,它在本地约束它而不是设置类级别范围变量。因此将其调整为list = new ListView()
。
另一方面,在GetTheData
函数中,项目来源被分配为list.ItemsSource = myList;
,需要更改为list.ItemsSource = Customers;
。
我已将zip文件重新打包并发送给您。如果这对您有用,请告诉我?您现在应该能够在 ListView 中看到所有客户。