muak / AiForms.SettingsView

SettingsView for Xamarin.Forms
MIT License
316 stars 45 forks source link

NullReferenceException with very basic SettingsView with RadioCells (not eveng with bindings) #167

Closed spenol closed 3 years ago

spenol commented 3 years ago

Description

Whenever I run a SettingsView page on Android, I get a System.NullReferenceException. This is even with a very basic page with the Picker control (see example below). Even when I remove the bindings, I still get the same error. Note the example below doesn't include bindings which clearly I'd like, but just wanted to keep the example as simple as possible....

Note it seems to work fine in iOS for me, including when bindings are included in the SelectedValue

            <sv:SettingsView HasUnevenRows="True"
                             CellValueTextFontSize="Medium"
                             >
                <sv:Section Title="Output format"
                            sv:RadioCell.SelectedValue="png">
                    <sv:RadioCell Title="Option 1" Description="Option 1 description" Value="png"/>
                    <sv:RadioCell Title="Option 2" Description="Option 2 description" Value="pdf"/>
                </sv:Section>
                <sv:Section Title="Size and quality"
                            sv:RadioCell.SelectedValue="default">
                    <sv:RadioCell Title="Option 1" Description="Option 1 descirption"
                                  Value="default"/>
                    <sv:RadioCell Title="Another"
                                  Description="...to be added soon"
                                  IsEnabled="False"/>
                </sv:Section>
                <sv:Section Title="Style and background">
                    <sv:LabelCell Title="Coming soon!" IsEnabled="False"/>
                </sv:Section>
            </sv:SettingsView>

Steps to Reproduce

  1. Add the XAML code above to a Xamarin Forms project
  2. Call the view
  3. NullReferenceException / Object reference not set to an instance of an object received

Expected Behavior

The controls should display properly

Actual Behavior

I get the following stacktrace (regardless of whether the SelectedValue is bound or not)

at AiForms.Renderers.Droid.RadioCellView.UpdateSelectedValue () [0x0000b] in <60ffaff25912480a962ef012c7b17bad>:0 at AiForms.Renderers.Droid.RadioCellView.UpdateCell () [0x00006] in <60ffaff25912480a962ef012c7b17bad>:0 at AiForms.Renderers.Droid.CellBaseRenderer`1[TnativeCell].GetCellCore (Xamarin.Forms.Cell item, Android.Views.View convertView, Android.Views.ViewGroup parent, Android.Content.Context context) [0x00046] in <60ffaff25912480a962ef012c7b17bad>:0 at Xamarin.Forms.Platform.Android.CellRenderer.GetCell (Xamarin.Forms.Cell item, Android.Views.View convertView, Android.Views.ViewGroup parent, Android.Content.Context context) [0x00075] in D:\a\1\s\Xamarin.Forms.Platform.Android\Cells\CellRenderer.cs:51 at Xamarin.Forms.Platform.Android.CellFactory.GetCell (Xamarin.Forms.Cell item, Android.Views.View convertView, Android.Views.ViewGroup parent, Android.Content.Context context, Xamarin.Forms.View view) [0x0001e] in D:\a\1\s\Xamarin.Forms.Platform.Android\Cells\CellFactory.cs:20 at AiForms.Renderers.Droid.SettingsViewRecyclerAdapter.BindContentView (AiForms.Renderers.Droid.ContentBodyViewHolder holder, System.Int32 position) [0x00043] in <60ffaff25912480a962ef012c7b17bad>:0 at AiForms.Renderers.Droid.SettingsViewRecyclerAdapter.OnBindViewHolder (AndroidX.RecyclerView.Widget.RecyclerView+ViewHolder holder, System.Int32 position) [0x00100] in <60ffaff25912480a962ef012c7b17bad>:0 at AndroidX.RecyclerView.Widget.RecyclerView+Adapter.n_OnBindViewHolder_Landroidx_recyclerview_widget_RecyclerView_ViewHolder_I (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_holder, System.Int32 position) [0x00010] in D:\a\1\s\generated\androidx.recyclerview.recyclerview\obj\Release\monoandroid9.0\generated\src\AndroidX.RecyclerView.Widget.RecyclerView.cs:430 at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.126(intptr,intptr,intptr,int)

Platforms

Basic Information

Screenshots

Reproduction Link

Workaround

spenol commented 3 years ago

It turned out I wasn't setting the 'Value' for the last RadioCell. Upon doing this the issue went away.