I have two classes and a WPF window. The two classes are ShellViewModel.cs and UnitStatusTab.cs and the WPF windows is called Shell.xaml. The ShellViewModel.cs is where most of the variables of the initialized so that they could be used in other classes and throughtout the project. Shell.xaml has a datagrid and displays a much of data. To retrieve that data from files the UnitStatusTab.cs is used but for some reason I'm getting the error
NullReferenceException was unhandled
This is some of the code in ShellViewModel.cs
public class ShellViewModel : INotifyPropertyChanged
{
Shell sh;
readonly Shell shell;
string PROBE_FOLDER = Config.GetDir(1);
string RAC_FOLDER = Config.GetDir(2);
string MMU_FOLDER1 = Config.GetDir(3);
string MMU_FOLDER2 = Config.GetDir(4);
public string User = "";
public string Pass = "";
public Thread initialOpen;
public Thread InputThread;
public Thread RACInputThread;
public Thread MMUThread;
public Thread ProbeThread;
public string unitStatusBaseFileName = @"unit_status_";
public string loadForecastBaseFileName = @"submitted_virtual_bids_";
public DateTime inputdate;
public bool Is_HDIC = true;
public ShellViewModel(Shell shell)
{
this.shell = shell;
IsIdle = true;
IsSchedRateCalcIdle = true;
ObsLog = new ObservableCollection<LogItem>();
ObsProbeLog = new ObservableCollection<LogItem>();
//obsDate = (DateTime.Now.Date).AddDays(1.0); // Commented this out so that current day date will be listed
obsDate = DateTime.Now.Date;
ObsRawDate = DateTime.Now.AddDays(-2);
obsScen = "1";
ObsProbeFolder = PROBE_FOLDER;
ObsInputFolder = Path.Combine(Path.Combine(RAC_FOLDER, ObsDate.ToString("yyyyMMdd")),Path.Combine( "AC2", "Probe Input_CTO"));
ObsInputFolderRAC = Path.Combine(Path.Combine(RAC_FOLDER, inputdate.ToString("yyyyMMdd")), Path.Combine("AC2", "Probe Input_t"));
ObsOutputFolder = Path.Combine(Path.Combine(RAC_FOLDER, ObsDate.ToString("yyyyMMdd")), Path.Combine("AC2", "Probe Output_CTO"));
ProbeXmlFactory factory = new ProbeXmlFactory();
//ObsProbeOptions = new ObservableCollection<ProbeOption>(factory.CreateProbeOptions(Path.Combine(PROBE_FOLDER, "ProbeRAC_AM.xml")));
ProbeInputEngine.Current.LogEvent += s => Log(s);
}
}
This is my code in UnitStatusTab.cs
public class UnitStatusTab
{
ShellViewModel shellVM;
Shell shell;
public void GetUnitStatusData()
{
this.shellVM = shellVM;
for (int i = 1; i <= 24; i++)
{
obsStartHours.Add(i);
obsEndHours.Add(i);
}
ObsUnitStatuses = new List<string>() { "A", "P", "M", "U", "*" };
ObsStartHour = 1;
ObsEndHour = 1;
ObsSelectedStatus = "A";
//ObsSelectedUnit = ObsUnits.FirstOrDefault();
string filePath;
filePath = System.IO.Path.Combine(shellVM.ObsInputFolder, @"unit_status_" + shellVM.ObsDate.ToString("yyyyMMdd") + ".csv");
shellVM.unitStatusBaseFileName = @"unit_status_";
}
This is the line where I'm getting the error on:
filePath = System.IO.Path.Combine(shellVM.ObsInputFolder, @"unit_status_" + shellVM.ObsDate.ToString("yyyyMMdd") + ".csv");
I've tried fixing it by replacing ShellViewModel shellVM;
with ShellViewModel shellVM = new ShellViewModel();
but thats giving me another error
'ShellViewModel' does not contain a constructor that takes 0 arguments