Android System.NullReferenceException with multi axis in Flexchart

Posted by: jeremytischuk on 13 February 2019, 10:14 am EST

    • Post Options:
    • Link

    Posted 13 February 2019, 10:14 am EST

    I have a line chart that has three series. The first two add fine when no axis is defined but when I need to add a second axis for the third series it give me this error. I have attached the on appearing section for the code where the error is generated.

    The pieces to know from my view model in the attached code are:

    ChartSeries: holds the data for the different series as floats and their log time as DateTime.

    FirstAxisItems and SecondAxisItems: List of up to 3 fields of the same graphing group to denote they are on the same axis. The data is formatted so it will add FirstAxisItems first then SecondAxisItems to the ChartSeries and FirstAxisItems will always have 1 item in it but SecondAxisItems can be null or empty.

    02-12 17:33:38.569 I/MonoDroid(17113): UNHANDLED EXCEPTION:

    02-12 17:33:38.631 I/MonoDroid(17113): System.NullReferenceException: Object reference not set to an instance of an object.

    02-12 17:33:38.632 I/MonoDroid(17113): at C1.Xamarin.Forms.Chart.Platform.Android.XSeries.ConvertAxisYToNative (C1.Android.Chart.ChartSeries NSeries, C1.Xamarin.Forms.Chart.ChartSeries XSeries, C1.Android.Chart.FlexChart NChart) [0x00010] in :0

    02-12 17:33:38.632 I/MonoDroid(17113): at C1.Xamarin.Forms.Chart.Platform.Android.XSeries.SeriesPropertyChanged (C1.Android.Chart.ChartSeries NSeries, C1.Xamarin.Forms.Chart.ChartSeries XSeries, System.String propertyName, C1.Android.Chart.FlexChart NChart) [0x001b2] in :0

    02-12 17:33:38.632 I/MonoDroid(17113): at C1.Xamarin.Forms.Chart.Platform.Android.XSeries.ToNative (C1.Xamarin.Forms.Chart.ChartSeries XSeries, C1.Android.Chart.FlexChart NChart) [0x00024] in :0

    02-12 17:33:38.632 I/MonoDroid(17113): at C1.Xamarin.Forms.Chart.Platform.Android.FlexChartRenderer.OnFlexChartSeriesChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x0003d] in :0

    02-12 17:33:38.632 I/MonoDroid(17113): at System.Collections.ObjectModel.ObservableCollection

    1[T].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00018] in /Users/builder/jenkins/workspace/xamarin-android-d15-9/xamarin-android/external/mono/external/corefx/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs:263  02-12 17:33:38.632 I/MonoDroid(17113):   at System.Collections.ObjectModel.ObservableCollection
    1[T].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedAction action, System.Object item, System.Int32 index) [0x00000] in /Users/builder/jenkins/workspace/xamarin-android-d15-9/xamarin-android/external/mono/external/corefx/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs:338

    02-12 17:33:38.632 I/MonoDroid(17113): at System.Collections.ObjectModel.ObservableCollection
    1[T].InsertItem (System.Int32 index, T item) [0x0001a] in /Users/builder/jenkins/workspace/xamarin-android-d15-9/xamarin-android/external/mono/external/corefx/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs:196  02-12 17:33:38.632 I/MonoDroid(17113):   at System.Collections.ObjectModel.Collection
    1[T].Add (T item) [0x00020] in /Users/builder/jenkins/workspace/xamarin-android-d15-9/xamarin-android/external/mono/external/corefx/src/Common/src/CoreLib/System/Collections/ObjectModel/Collection.cs:73

    02-12 17:33:38.632 I/MonoDroid(17113): at TechCheck.Views.ControllerGraphPage.OnAppearing () [0x00585] in C:\Users\JeremyTischuk\source\repos\TechCheck\TechCheck\TechCheck\Views\ControllerGraphPage.xaml.cs:120

    02-12 17:33:38.632 I/MonoDroid(17113): at Xamarin.Forms.Page.SendAppearing () [0x00024] in D:\a\1\s\Xamarin.Forms.Core\Page.cs:316

    02-12 17:33:38.632 I/MonoDroid(17113): at Xamarin.Forms.Platform.Android.AppCompat.FragmentContainer.SendLifecycleEvent (System.Boolean isAppearing) [0x0004f] in D:\a\1\s\Xamarin.Forms.Platform.Android\AppCompat\FragmentContainer.cs:132

    02-12 17:33:38.632 I/MonoDroid(17113): at Xamarin.Forms.Platform.Android.AppCompat.FragmentContainer.OnResume () [0x00011] in D:\a\1\s\Xamarin.Forms.Platform.Android\AppCompat\FragmentContainer.cs:117

    02-12 17:33:38.632 I/MonoDroid(17113): at Android.Support.V4.App.Fragment.n_OnResume (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] in <21e4bb539f4a49b58a498749b367d2a8>:0

    02-12 17:33:38.632 I/MonoDroid(17113): at (wrapper dynamic-method) System.Object.44(intptr,intptr)

    02-12 17:33:38.667 W/art (17113): JNI RegisterNativeMethods: attempt to register 0 native methods for android.runtime.JavaProxyThrowable

    02-12 17:33:38.672 D/Mono (17113): DllImport searching in: ‘__Internal’ (‘(null)’).

    02-12 17:33:38.672 D/Mono (17113): Searching for ‘java_interop_jnienv_throw’.

    02-12 17:33:38.672 D/Mono (17113): Probing ‘java_interop_jnienv_throw’.

    02-12 17:33:38.672 D/Mono (17113): Found as ‘java_interop_jnienv_throw’.

  • Posted 15 February 2019, 4:59 am EST

    Hi Pete,

    Thanks for sharing the code with us, the issue can be replicated at our end. We have escalated the issue to the concerned team and will let you know once we hear from them.

    Any specific reason that you are setting the Chart and ChartAxis property in the OnAppearing method?

    In the meantime you can use the following workaround

    We are using the similar code in the constructor of the content page and it is working fine.

    For reference please see the attached sample.

    Thanks

    ChartIssue.zip

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels