" NullReferenceException was unhandled, Object reference not set to an instance of an object."
in one of the form needing data.....
public string IDSet
{
set { tb_IdFunc.Text = value; }
}
public string NomeSet
{
set { lbNomeFunc.Text = value; }
}
private void bt_Search_Click(object sender, EventArgs e)
{
if (tb_IdFunc.Text == "")
{
frmSearchFunc SF = new frmSearchFunc();
SF.Location = new System.Drawing.Point(CG.parameterXLocation(), CG.parameterYLocation());
SF.ShowDialog();
}
else
{
FuncDal.shearchFaltaID(this.lstFalta, this.dtDataFalta.Value.Month, this.dtDataFalta.Value.Year, Convert.ToInt32(this.tb_IdFunc.Text));
this.lbNomeFunc.Text = FuncDal.getFuncNam(this.tb_IdFunc.Text);
}
}
In search form.....
private void lstSearchFuncGeral_DoubleClick(object sender, EventArgs e)
{
//frmAtribuirFalta atribF = new frmAtribuirFalta();
frmAtribuirFalta atribF = (frmAtribuirFalta)Application.OpenForms["frmAtribuirFalta"];
configSubsidio cnfgSubs = (configSubsidio)Application.OpenForms["configSubsidio"];
try
{
if (atribF.Visible == true)
{
arrayDetail = FuncDal.FuncAllData(this.lstSearchFuncGeral.FocusedItem.SubItems[0].Text);
//nomeProp = arrayDetail[0].ToString().Trim() + " " + arrayDetail[17].ToString().Trim();
atribF.IDSet = dadosID;
atribF.NomeSet = dadosNome;
}
}
catch (Exception ex)
{
throw ex;
}
try
{
if (cnfgSubs.Visible == true)
{
arrayDetail = FuncDal.FuncAllData(this.lstSearchFuncGeral.FocusedItem.SubItems[0].Text);
cnfgSubs.IDSet = dadosID;
cnfgSubs.NomeSet = dadosNome;
}
}
catch (Exception ex)
{
throw ex;
}
this.Close();
}
Regards!
Regards!
Sousa PamboPosted Aug 16, 2014, 4:32 PM
Still the same nothing has changed. I'll find another way to get data. I'll keep searching a solution but now I have to keep working in my project it will work anyway. Thanks a lot. I'll keep asking....be fine!
VulpesPosted Aug 15, 2014, 9:00 AM
If FuncDal is a class name rather than a variable, then omit the first 'if' statement otherwise it won't compile.
Sousa PamboPosted Aug 15, 2014, 8:07 AM
I did as u said, I used the break-point, the result...can see the bolded lines, I can't analyse it. I don't whether the error is the first bolded line or the second...
VulpesPosted Aug 13, 2014, 7:47 PM
What I'd suggest is that you put a break-point on the first line of the method and then 'single step' through it, hovering your mouse over the variables as you go, until you find one that's null.
Sousa PamboPosted Aug 13, 2014, 4:43 PM
now i'm really lost. Is there a way to solve this problem?
Or I'll have to use one search form to each form needing data....
what do you suggest?
VulpesPosted Aug 13, 2014, 6:52 AM
Application.OpenForms will only get a reference to the forms if they've already been instantiated and are currently open. Otherwise it will return null and, when you attempt to cast to the actual form type, a null reference exception will be thrown.
However, this exception will be thrown BEFORE the first try block is even reached and so won't be caught at all.
Sousa PamboPosted Aug 13, 2014, 6:42 AM
I think I got the point. I used
for this way it shows the error after keep works normally.
Then I used ... frmAtribuirFalta atribF = new frmAtribuirFalta();
instead... //frmAtribuirFalta atribF = (frmAtribuirFalta)Application.OpenForms["frmAtribuirFalta"];
it works for another form, but this one doesn't get data from search form.
I think the point is... I have to instanciate the forms, but doing that it won't get the data from the search data form
VulpesPosted Aug 12, 2014, 9:57 AM
Sousa PamboPosted Aug 12, 2014, 7:57 AM
VulpesPosted Aug 12, 2014, 7:36 AM
throw ex;
try just printing out the error message:
MessageBox.Show(ex.Message);
Sousa PamboPosted Aug 12, 2014, 7:09 AM
When I comment the line ..... (I bolded those line) it works, but it doesn't accept when its more than one. I don't get the conflict here.
VulpesPosted Aug 12, 2014, 6:40 AM
If FuncDal is an object reference rather than a class name, perhaps that could be null.
If there is currently no focused item in the ListView, then this.lstSearchFuncGeral.FocusedItem will be null.
Sousa PamboPosted Aug 12, 2014, 6:26 AM
Please see the bolded comment
VulpesPosted Aug 12, 2014, 6:11 AM