0

When adding a footer to the MvxListView, an exception is thrown when navigating away from the activity/fragment when the view is destroyed:

05-30 11:22:12.164 I/MonoDroid(27621): UNHANDLED EXCEPTION:
05-30 11:22:12.171 I/MonoDroid(27621): System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object.
05-30 11:22:12.171 I/MonoDroid(27621):   at MvvmCross.Platforms.Android.Binding.Views.MvxListView.set_ItemsSource (System.Collections.IEnumerable value) [0x00006] in <dcc1f804568a45a5accd2fb0ee5e5ebf>:0 
05-30 11:22:12.171 I/MonoDroid(27621):   at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&)
05-30 11:22:12.171 I/MonoDroid(27621):   at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
05-30 11:22:12.171 I/MonoDroid(27621):    --- End of inner exception stack trace ---
05-30 11:22:12.171 I/MonoDroid(27621):   at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0004b] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
05-30 11:22:12.171 I/MonoDroid(27621):   at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
05-30 11:22:12.171 I/MonoDroid(27621):   at MvvmCross.Binding.Bindings.Target.MvxPropertyInfoTargetBinding.SetValueImpl (System.Object target, System.Object value) [0x0000c] in <dcc1f804568a45a5accd2fb0ee5e5ebf>:0 
05-30 11:22:12.171 I/MonoDroid(27621):   at MvvmCross.Binding.Bindings.Target.MvxConvertingTargetBinding.SetValue (System.Object value) [0x00090] in <dcc1f804568a45a5accd2fb0ee5e5ebf>:0 
05-30 11:22:12.171 I/MonoDroid(27621):   at MvvmCross.Binding.Bindings.Target.MvxPropertyInfoTargetBinding.Dispose (System.Boolean isDisposing) [0x00013] in <dcc1f804568a45a5accd2fb0ee5e5ebf>:0 
05-30 11:22:12.171 I/MonoDroid(27621):   at MvvmCross.Binding.Bindings.Target.MvxWithEventPropertyInfoTargetBinding.Dispose (System.Boolean isDisposing) [0x0001d] in <dcc1f804568a45a5accd2fb0ee5e5ebf>:0 
05-30 11:22:12.171 I/MonoDroid(27621):   at MvvmCross.Binding.Bindings.MvxBinding.Dispose () [0x00000] in <dcc1f804568a45a5accd2fb0ee5e5ebf>:0 
05-30 11:22:12.171 I/MonoDroid(27621):   at MvvmCross.Binding.Bindings.MvxFullBinding.ClearTargetBinding () [0x00039] in <dcc1f804568a45a5accd2fb0ee5e5ebf>:0 
05-30 11:22:12.171 I/MonoDroid(27621):   at MvvmCross.Binding.Bindings.MvxFullBinding.Dispose (System.Boolean isDisposing) [0x00003] in <dcc1f804568a45a5accd2fb0ee5e5ebf>:0 
05-30 11:22:12.171 I/MonoDroid(27621):   at MvvmCross.Binding.Bindings.MvxBinding.Dispose () [0x00000] in <dcc1f804568a45a5accd2fb0ee5e5ebf>:0 
05-30 11:22:12.171 I/MonoDroid(27621):   at MvvmCross.Binding.BindingContext.MvxBindingContext.ClearAllViewBindings () [0x00032] in <dcc1f804568a45a5accd2fb0ee5e5ebf>:0 
05-30 11:22:12.171 I/MonoDroid(27621):   at MvvmCross.Binding.BindingContext.MvxBindingContext.ClearAllBindings () [0x00000] in <dcc1f804568a45a5accd2fb0ee5e5ebf>:0 
05-30 11:22:12.171 I/MonoDroid(27621):   at MvvmCross.Droid.Support.V4.EventSource.MvxBindingFragmentAdapter.HandleDestroyViewCalled (System.Object sender, System.EventArgs e) [0x0000f] in <dffbd2c347de4e08a5c9f76935e21411>:0 
05-30 11:22:12.171 I/MonoDroid(27621):   at MvvmCross.Base.MvxDelegateExtensions.Raise (System.EventHandler eventHandler, System.Object sender) [0x00003] in <dcc1f804568a45a5accd2fb0ee5e5ebf>:0 
05-30 11:22:12.171 I/MonoDroid(27621):   at MvvmCross.Droid.Support.V4.EventSource.MvxEventSourceFragment.OnDestroyView () [0x00000] in <dffbd2c347de4e08a5c9f76935e21411>:0 
05-30 11:22:12.171 I/MonoDroid(27621):   at Android.Support.V4.App.Fragment.n_OnDestroyView (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] in <3682f8af23a748128467fbf9c57ae876>:0 
05-30 11:22:12.171 I/MonoDroid(27621):   at (wrapper dynamic-method) System.Object.7b7dc7e9-7935-455b-98b9-fc1831f50a54(intptr,intptr)

The list view is created using the following XAML:

<Mvx.MvxListView
    android:id="@+id/voucher_list_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:MvxItemTemplate="@layout/voucher_list_item"
    app:MvxBind="ItemsSource Vouchers" />

And the footer is added using:

var listView = view.FindViewById<MvxListView>(Resource.Id.voucher_list_view);
var footerView = this.BindingInflate(Resource.Layout.voucher_list_footer, null);
listView.AddFooterView(footerView, null, false);

This is the footers XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/voucher_list_footer"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <ProgressBar
        android:id="@+id/progressBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:MvxBind="Visibility Visibility(IsLoading)" />
    <android.support.v7.widget.AppCompatButton
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Hent flere bilag"
        style="@style/Widget.AppCompat.Button.Borderless"
        app:MvxBind="Visibility Visibility(CanLoadMore); Click LoadVouchersCommand" />
</LinearLayout>

When removing the footer, the view is destroyed correctly. Any idea what is causing this issue?

FreakyAli
  • 13,349
  • 3
  • 23
  • 63
Tommy Jakobsen
  • 2,323
  • 6
  • 39
  • 66
  • It is NullPointException. What is your problem? I found [listview-addfooterview-issue](https://stackoverflow.com/questions/36739194/android-listview-addfooterview-issue) and [how to add footerView](https://stackoverflow.com/questions/4265228/how-to-add-a-footer-in-listview) – Robbit May 31 '18 at 08:05
  • Sorry for the late reply @JoeLv-MSFT. Well the issue is that exception. As described, it happens when navigating away from the view, and only when the footer is added to the list view. Those links doesn't seem too relevant to this? None of them are using Xamarin/MvvmCross. – Tommy Jakobsen Jun 04 '18 at 18:28

0 Answers0