Oxyplot excepttion: Object reference not set to an instance of an object.

royazamroyazam USMember
edited August 2017 in General

I am using the oxyplot view to show some data in a diagram. It has been working correctly until yesterday. Since yesterday, whenever I open the activity page included oxyplot, it just shows this message on the mobile screen:

Oxyplot excepttion: Object reference not set to an instance of an object. an exception of type system.NullReferenceException was thrown at Oxyplot.ReflectionPath..ctor(System.String path)[0x00006]

I tried to find where it has happened by putting a breakpoint when a system.NullReferenceException was thrown but the program was not stopped.

Adding a plotview control to the user interface in my activity:

                             design d = new design();
        energyConsumption eConsumption = new energyConsumption();


        var plotView = new PlotView(this);


        energyBarsList = eConsumption.timerClass();

        plotView.Model = d.CreatePlotModel(energyBarsList);

        this.AddContentView(plotView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent));

The class CreatePlotModel:

         public PlotModel CreatePlotModel(float[] energyValue)
{

    var plotModel = new PlotModel { Title = "Two Hourly Energy Consumption",
        LegendPlacement = LegendPlacement.Outside,
        LegendPosition = LegendPosition.BottomCenter,
        LegendOrientation = LegendOrientation.Horizontal,
        LegendBorderThickness = 0
    };
    plotModel.PlotType = PlotType.XY;


    var barSeries = new BarSeries
     {
            ItemsSource = new List<BarItem>(new[]
    {
                new BarItem{ Value = (energyValue[0] ) },
                new BarItem{ Value = (energyValue[1] ) },
                new BarItem{ Value = (energyValue[2] ) },
                new BarItem{ Value = (energyValue[3] ) },
                new BarItem{ Value = (energyValue[4] ) },
                new BarItem{ Value = (energyValue[5] ) },
                new BarItem{ Value = (energyValue[6] ) },
                new BarItem{ Value = (energyValue[7] ) },
                new BarItem{ Value = (energyValue[8] ) },
                new BarItem{ Value = (energyValue[9] ) },
                new BarItem{ Value = (energyValue[10] ) },
                new BarItem{ Value = (energyValue[11] ) }


    }),


        LabelPlacement = LabelPlacement.Inside,

        LabelFormatString = "{0:.00}%"
    };

    plotModel.Series.Add(barSeries);
    plotModel.Axes.Add(new CategoryAxis
    {
        Position = AxisPosition.Left,
        Key = "Hours",
        ItemsSource = new[]
{
        "0-2",
        "2-4",
        "4-6",
        "6-8",
        "8-10",
        "10-12",
        "12-14",
        "14-16",
        "16-18",
        "20-22",
        "22-24"
}
    });


    return plotModel;

    }

I would be thankful if you know how to solve it.

Tagged:
Sign In or Register to comment.