【问题标题】:Xamarin.Forms Unhandled ExceptionXamarin.Forms 未处理的异常
【发布时间】:2016-08-11 01:22:57
【问题描述】:

我正在我的项目中尝试 CarouselView。但是当我运行我的项目时,我得到了这个错误。

这是我的 xaml 代码;

<?xml version="1.0" encoding="UTF-8"?>
<base:HotelDetailPageXaml
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="XamarinCRM.Pages.Hotels.HotelDetailPage"
xmlns:statics="clr-namespace:XamarinCRM.Statics"
xmlns:base="clr-namespace:XamarinCRM.Pages.Hotels"
xmlns:hotelViews="clr-namespace:XamarinCRM.Views.Hotels"
xmlns:i18n="clr-namespace:XamarinCRM.Localization"
xmlns:cv="clr-namespace:Xamarin.Forms;assembly=Xamarin.Forms.CarouselView"
    Title="{Binding Hotel.Name}">
  <base:HotelDetailPageXaml.Content>
        <StackLayout Spacing="0">          
          <cv:CarouselView ItemsSource="{Binding Hotel.HotelImages}">
            <cv:CarouselView.ItemTemplate>
              <DataTemplate>
                <StackLayout HeightRequest="200">
                  <Image HeightRequest="200" Aspect="AspectFill" Source="{Binding FullPath}"/>
                </StackLayout>
              </DataTemplate>
            </cv:CarouselView.ItemTemplate>
          </cv:CarouselView>
  </StackLayout>
  </base:HotelDetailPageXaml.Content>
</base:HotelDetailPageXaml>

这里是我调用的json服务;

 public async Task<IEnumerable<HotelModel>> GetHotelsAsync(bool includeLeads = false)
        {
            string path = "my service url";
            HttpClient Client = new HttpClient();
            var task = await Client.GetAsync(path);
            var jsonString = await task.Content.ReadAsStringAsync();
            List<HotelModel> hotelList = new List<HotelModel>();
            List<HotelImageModel> hotelImageList = new List<HotelImageModel>();
            dynamic json = JsonConvert.DeserializeObject(jsonString);   

                        for (int j = 0; j < 10; j++)
                        {
                            HotelImageModel hotelImage = new HotelImageModel();    
                            hotelImage.FullPath = json["data"][i]["HotelImages"][j]["FullPath"].Value;    
                            hotel.HotelImages.Add(hotelImage);
                        }
                    }

i 是 for 的酒店索引号,j 是酒店的图像索引号

【问题讨论】:

  • 看起来你有一个例外。 :-) 请发布失败的代码和完整的堆栈跟踪。避免将文字作为照片发布。
  • 我已经添加了更多细节......请看这个。

标签: xamarin xamarin.ios xamarin.forms


【解决方案1】:

在 Xamarin 的论坛上报告这个错误就像是一个 bug 一样的错误。 6 月 21 日

https://forums.xamarin.com/discussion/69483/why-does-carouselview-crash-on-android

您安装了哪个版本的 Xamarin?您尝试安装最新版本的 xamarin?

【讨论】:

  • 我添加了更多细节。
  • 我更新答案让我知道你是否解决了问题。问候
  • 不幸的是,我已经看到了这份报告,但它不像我的错误。我正在使用 Xamarin 4.1.1。
  • 尝试更新您的版本。你说那不是你的错误正是你的错误。 @ozmert75 异常:System.MethodAccessException:方法Xamarin.Forms.BindingBase:TryGetSynchronizedCollection (System.Collections.IEnumerable,Xamarin.Forms.CollectionSynchronizationContext&amp;)' is inaccessible from method Xamarin.Forms.ItemsView/ItemsSourceProxy:get_SyncContext ()'
  • 我正在尝试,我会把结果分享给你,谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-07-18
  • 2011-11-19
  • 1970-01-01
  • 1970-01-01
  • 2011-01-16
相关资源
最近更新 更多