Linq object reference not set

  • Thread starter Thread starter Andrei Ciopas
  • Start date Start date
A

Andrei Ciopas

Guest
Hello , I just started with xamarin and c# and i struggle to understand why i'm getting this error here's my code it's supposed to be searching in list using linq and displaying the selected element in the list based on "Fixtureid" from a guide i found on youtube , the video its a bit old but i tought it might still be good .

namespace FixtAppl
{
[Activity(Label = "Fixture")]
public class Fixture : Activity
{
private List<Fixture_List> mItems;
public ListView fixList;
public EditText fixSearch;
private CustomAdapter fixtAdapter;

protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);


//Set View
SetContentView(Resource.Layout.Fixture);
//Set View
//ViewConnect
fixList = FindViewById<ListView>(Resource.Id.FixtureList);
EditText fixSearch = FindViewById<EditText>(Resource.Id.FixSearch);
fixSearch.Alpha = 0;
fixSearch.TextChanged += FixSearch_TextChanged;
//ViewConnect

// List
mItems = new List<Fixture_List>
{
new Fixture_List { FixtureId = "9771", FixtureName = "VNC 8 - LED ARRAY LH", FixtureRaft = "01", FixtureNumar = "01" },
new Fixture_List { FixtureId = "9772", FixtureName = "VNC 8 - LED ARRAY RH", FixtureRaft = "01", FixtureNumar = "02" },
new Fixture_List { FixtureId = "9773", FixtureName = "VNC 8 - Led DRIVE MODULE", FixtureRaft = "01", FixtureNumar = "03" },
new Fixture_List { FixtureId = "1877", FixtureName = "VNC 1 - INNER TAIL", FixtureRaft = "01", FixtureNumar = "04" },
new Fixture_List { FixtureId = "1878", FixtureName = "VNC 1 - INNER TAIL", FixtureRaft = "01", FixtureNumar = "04" },
new Fixture_List { FixtureId = "6181", FixtureName = "VNC 1 - LDM", FixtureRaft = "01", FixtureNumar = "05" },
new Fixture_List { FixtureId = "6184", FixtureName = "VNC 1 - LDM", FixtureRaft = "01", FixtureNumar = "05" },

}

fixtAdapter = new CustomAdapter(this, mItems);
fixList.Adapter = fixtAdapter;


}

private void FixSearch_TextChanged(object sender, TextChangedEventArgs e)
{
List<Fixture_List> searchFixture = (from fixt in mItems where fixt.FixtureId.Contains(fixSearch.Text) select fixt).ToList();
fixtAdapter = new CustomAdapter(this, searchFixture);
fixList.Adapter = fixtAdapter;
}
}
}
The error i'm getting is this

System.NullReferenceException: Object reference not set to an instance of an object.

Here's a photo of the error i'm getting maybe it helps

View: https://imgur.com/E9xbux2


The line's of code that i'm getting the error in are those

private void FixSearch_TextChanged(object sender, TextChangedEventArgs e)
{
List<Fixture_List> searchFixture = (from fixt in mItems where fixt.FixtureId.Contains(fixSearch.Text) select fixt).ToList();
fixtAdapter = new CustomAdapter(this, searchFixture);
fixList.Adapter = fixtAdapter;
}

Continue reading...
 
Back
Top