code crashes app

EwoudvdWerfEwoudvdWerf USMember ✭✭✭

This code code crashes my app iOS

How i called the code (maybe usefull to know)
SetString();

The code:
public async void SetString() { var client = new HttpClient(); var data = await client.GetStringAsync("http://www.topentwelonline.nl/json/news.json?count=1"); InternetLabel.Text = data; }

Best Answer

Answers

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    which is the exception?

  • NMackayNMackay GBInsider, University mod

    put a try catch round your code to see the error stack, as it stands if that codes faults you app will terminate.

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    In Xamarin Studio you can take a look (if you are in Debug) to Application Output TAB

  • EwoudvdWerfEwoudvdWerf USMember ✭✭✭

    @NMackay @AlessandroCaliaro got this
    Xamarin.Forms.Xaml.XamlParseException: Position 7:10. Property Content is null or is not IEnumerable

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    It's a problem in your XAML file, the same we have already solved... Have you inserted ALL you controls inside ONE StackLayout?

  • EwoudvdWerfEwoudvdWerf USMember ✭✭✭

    @AlessandroCaliaro no...
    <?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="TopEnTwelForms.Nieuws" Title="Nieuws"> <ContentPage.Content> <Label x:Name="InternetLabel" Text="..." FontSize="Large"/> <ListView x:Name="NieuwsList" RowHeight="110"> <ListView.ItemTemplate> <DataTemplate> <ViewCell> <ViewCell.View> <StackLayout Orientation="Horizontal" > <Image Source="{Binding ThumbnailSource}" HorizontalOptions="Start" WidthRequest="150" HeightRequest="100" VerticalOptions="Center"/> <Label FontSize="Large" Text="{Binding TextContent}" VerticalOptions="Center"/> </StackLayout> </ViewCell.View> </ViewCell> </DataTemplate> </ListView.ItemTemplate> </ListView> </ContentPage.Content> </ContentPage>

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭
    edited March 2017
    <?xml version="1.0" encoding="utf-8" ?>
    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 x:Class="TopEnTwelForms.Nieuws"
                 Title="Nieuws">
        <ContentPage.Content>
        <StackLayout>
                <Label x:Name="InternetLabel" Text="..." FontSize="Large"/>
                <ListView x:Name="NieuwsList" RowHeight="110">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <ViewCell>
                                <ViewCell.View>
                                    <StackLayout Orientation="Horizontal" >
                                        <Image Source="{Binding ThumbnailSource}" HorizontalOptions="Start" WidthRequest="150" HeightRequest="100" VerticalOptions="Center"/>
                                        <Label FontSize="Large" Text="{Binding TextContent}" VerticalOptions="Center"/>
                                    </StackLayout>
                                </ViewCell.View>
                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
        </StackLayout>
        </ContentPage.Content>
    </ContentPage>
    
  • NMackayNMackay GBInsider, University mod

    Also your trying to assign RSS data straight to a label.

    You need to deserialize your RSS feed into a manageable structure.

    https://forums.xamarin.com/discussion/57538/how-can-i-get-data-from-rss-feed-for-my-app

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭
    Accepted Answer

    Add a StackLayout

  • EwoudvdWerfEwoudvdWerf USMember ✭✭✭

    Thanks once again @AlessandroCaliaro next time i'm first checking the xaml file

Sign In or Register to comment.