如何修复使用滚动视图时 xamarin.android 预览中的 'java.lang.noclassdeffounderror' 错误

how to fix 'java.lang.noclassdeffounderror' error on xamarin.android preview when use scrollview

我尝试了下面的代码,但是 android 预览在使用滚动视图时不起作用,ios 预览工作正常只是不显示图像但是当 运行 项目结果in simulator 和 emulator 是真的,我的问题是预览

这是我的 xaml 页面:

<?xml version="1.0" encoding="utf-8"?>
<ContentPage Style="{StaticResource baseStyle}" xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:Flightio" x:Class="Flightio.MainPage"
             xmlns:ffimageloadingSVG="clr-namespace:FFImageLoading.Svg.Forms;assembly=FFImageLoading.Svg.Forms"
             xmlns:fftransformations="clr-namespace:FFImageLoading.Transformations;assembly=FFImageLoading.Transformations">
   <ContentPage.Content>
        <ScrollView>
            <Grid RowSpacing="8" x:Name="grid_Main">  
                <Grid.RowDefinitions>  
                    <RowDefinition Height="45" />  
                    <RowDefinition Height="75" />  
                    <RowDefinition Height="*" /> 
                </Grid.RowDefinitions>  
                <Grid.ColumnDefinitions>  
                    <ColumnDefinition Width="*" />  
                </Grid.ColumnDefinitions>  
                <Image Source="Logo.jpg" x:Name="image_logo" HorizontalOptions="Center" Margin="0,10,0,0"/>
                <RelativeLayout HorizontalOptions="FillAndExpand" x:Name="relLay_blueMenu" BackgroundColor="#1e559e" Grid.Row="1" Margin="10,0,10,0">  
                    <ContentView BackgroundColor="White" x:Name="view_domesticMenu"
                                 Margin="0,5,0,0"
                                 RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.8}"
                                 RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.2}"
                                 RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=1}">
                                 <RelativeLayout x:Name="relLay_flightMenu" HorizontalOptions="FillAndExpand">
                                    <Label Text="aliali" TextColor="Red" XAlign="Center" Margin="10,0,10,0"/>
                                 </RelativeLayout>
                    </ContentView>
                    <ContentView BackgroundColor="#1e559e" x:Name="view_internationalFlightMenu"
                                 Margin="0,5,0,0"
                                 RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.6}"
                                 RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.2}"
                                 RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=1}"></ContentView>
                    <ContentView BackgroundColor="#1e559e" x:Name="view_hotelMenu"
                                 Margin="0,5,0,0"
                                 RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.4}"
                                 RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.2}"
                                 RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=1}"></ContentView>
                    <ContentView BackgroundColor="#1e559e" x:Name="view_trianMenu"
                                 Margin="0,5,0,0"
                                 RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.2}"
                                 RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.2}"
                                 RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=1}"></ContentView>
                    <ContentView BackgroundColor="#1e559e" x:Name="view_busMenu"
                                 Margin="0,5,0,0"
                                 RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0}"
                                 RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.2}"
                                 RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=1}">
                       <Label Text="aliali2" TextColor="Blue" XAlign="Center"/>
                    </ContentView>
                </RelativeLayout>
<!--              <ffimageloadingSVG:SvgCachedImage Source="baseline-flight.svg" x:Name="image_logo2" HorizontalOptions="Center" Grid.Row="2"/>                                    -->
             </Grid>
            </ScrollView>
     </ContentPage.Content>
</ContentPage>

并且在使用滚动视图时 android 预览时出现此错误:

所以我有两个问题:

1- 如何修复我的 android 预览?

2- 如何在 ios 预览中显示图像?

1- how to fix my android preview?

我刚刚在我这边测试了你的 xaml 代码,它在预览中运行良好。

  1. 我使用Visual Studio Community 2017,版本(15.9.9)
  2. 您可以尝试清理并重建您的项目。
  3. 尝试重新启动您的 visual studio。

2- how show images in ios preview?

尝试去掉图片名称中的.jpg。例如:

<Image Source="Logo"/>

此外,请查看此处列出的提示:xaml-previewer-isnt-showing-or-shows-an-error

but when run the project the result in simulator and emulator is true

我认为模拟器和仿真器中的结果比预览中的结果更可靠。

我遇到了同样的问题,我通过更改 Android 项目的目标平台解决了它。

从 Android 9.0 (Pie) 到 Android 8.1 (Oreo) 在应用程序属性和 Android 清单中。