|
1 | | -# accordion-xamarin.forms-4.0-framework-issue |
2 | | -How to overcome the crash Java.Lang.NullPointerException in Xamarin.Forms Accordion (SfAccordion) |
| 1 | +# How to overcome the crash Java.Lang.NullPointerException in Xamarin.Forms Accordion (SfAccordion) |
| 2 | + |
| 3 | +In [SfAccordion](https://help.syncfusion.com/xamarin/accordion/getting-started?), When loading Label as direct children of [Header](https://help.syncfusion.com/cr/xamarin/Syncfusion.Expander.XForms~Syncfusion.XForms.Accordion.AccordionItem~Header.html?) or [Content](https://help.syncfusion.com/cr/xamarin/Syncfusion.Expander.XForms~Syncfusion.XForms.Accordion.AccordionItem~Content.html?) of [AccordionItem](https://help.syncfusion.com/cr/xamarin/Syncfusion.Expander.XForms~Syncfusion.XForms.Accordion.AccordionItem.html?), then it will lead to exception in Xamarin.Forms 4.0 and above version. |
| 4 | + |
| 5 | +However, the issue can be resolved in application level by loading Label inside Grid in **AccordionItem.Header** and **AccordionItem.Content**. |
| 6 | + |
| 7 | +You can also refer the following article. |
| 8 | + |
| 9 | +https://www.syncfusion.com/kb/11432/how-to-overcome-the-crash-java-lang-nullpointerexception-in-xamarin-forms-accordion |
| 10 | + |
| 11 | +**XAML** |
| 12 | + |
| 13 | +Loading Label inside **Header** and **Content** in Grid |
| 14 | +``` xml |
| 15 | +<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" |
| 16 | + xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" |
| 17 | + xmlns:syncfusion="clr-namespace:Syncfusion.XForms.Accordion;assembly=Syncfusion.Expander.XForms" |
| 18 | + x:Class="AccordionXamarin.MainPage" Padding="{OnPlatform iOS='0,40,0,0'}"> |
| 19 | + |
| 20 | + <ContentPage.Content> |
| 21 | + <syncfusion:SfAccordion ExpandMode="MultipleOrNone" > |
| 22 | + <syncfusion:SfAccordion.Items> |
| 23 | + <syncfusion:AccordionItem> |
| 24 | + <syncfusion:AccordionItem.Header> |
| 25 | + <Grid> |
| 26 | + <Label Text="Cheese burger" HeightRequest="50" VerticalTextAlignment="Center"/> |
| 27 | + </Grid> |
| 28 | + </syncfusion:AccordionItem.Header> |
| 29 | + <syncfusion:AccordionItem.Content> |
| 30 | + <Grid Padding="10" BackgroundColor="NavajoWhite"> |
| 31 | + <Label Text="Hamburger accompanied with melted cheese. The term itself is a portmanteau of the words cheese and hamburger. The cheese is usually sliced, then added a short time before the hamburger finishes cooking to allow it to melt." VerticalTextAlignment="Center"/> |
| 32 | + </Grid> |
| 33 | + </syncfusion:AccordionItem.Content> |
| 34 | + </syncfusion:AccordionItem> |
| 35 | + <syncfusion:AccordionItem> |
| 36 | + <syncfusion:AccordionItem.Header> |
| 37 | + <Grid> |
| 38 | + <Label Text="Veggie burger" HeightRequest="50" VerticalTextAlignment="Center"/> |
| 39 | + </Grid> |
| 40 | + </syncfusion:AccordionItem.Header> |
| 41 | + <syncfusion:AccordionItem.Content> |
| 42 | + <Grid Padding="10" BackgroundColor="NavajoWhite"> |
| 43 | + <Label Text="Veggie burger, garden burger, or tofu burger uses a meat analogue, a meat substitute such as tofu, textured vegetable protein, seitan (wheat gluten), Quorn, beans, grains or an assortment of vegetables, which are ground up and formed into patties." VerticalTextAlignment="Center"/> |
| 44 | + </Grid> |
| 45 | + </syncfusion:AccordionItem.Content> |
| 46 | + </syncfusion:AccordionItem> |
| 47 | + ... |
| 48 | + </syncfusion:SfAccordion.Items> |
| 49 | + </syncfusion:SfAccordion> |
| 50 | + </ContentPage.Content> |
| 51 | +</ContentPage> |
| 52 | +``` |
0 commit comments