|
Provide the code that is causing the problem and someone may be able to help you better.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
preetpal wrote: not breaking the normal execution and run the next line of code.
It is generally no good idea to ignore an exception. If you don't care in a certain situation if sth. is null, then you should check that before with an if-statement.
What you are describing sounds like a flaw in your control flow...
Regards
Thomas
www.thomas-weller.de
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Programmer - an organism that turns coffee into software.
|
|
|
|
|
thx
my code which is causing error is below
XmlNodeList rows = iElement.SelectNodes("./TBODY/TR");
_callerFirstName = rows[2].ChildNodes[0].InnerText.Trim();
_callerLastName = rows[2].ChildNodes[1].InnerText.Trim();
_callerPhone = rows[4].ChildNodes[0].InnerText.Trim();
_callerDept = rows[4].ChildNodes[1].InnerText.Trim();
_callerUserID = rows[6].FirstChild.InnerText.Trim();//error
_callerEMail = rows[8].FirstChild.InnerText.Trim();
user id id null in the html page so i am getting error
its like i can get anything as blank in html page as of now userid is blank
|
|
|
|
|
I'm afraid I don't really get your problem. You are trying to dereference sth. that is null , so you get an exception. This is absolutely correct. I'd be very afraid if I'd see sth. other than that. As I said: Check for null at the appropriate places! Don't try to save typings in the first place.
Remember:
Programming is not about writing the shortest possible code, but about writing code as correct, robust, and readable as possible.
Regards
Thomas
www.thomas-weller.de
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Programmer - an organism that turns coffee into software.
|
|
|
|
|
preetpal wrote: user id id null in the html page so i am getting erro
So, this is an ASP.NET question ?
This code just plain sucks. You should not be accessing child nodes by index, but by name. Your code is illegible and hard to maintain.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
string getVal(XmlNode node) {
return (node == null ? null : node.InnerText.Trim);
}
|
|
|
|
|
Hello ,
I want to thank you for your great Facebook articles.
I have a question on FaceBook API , is it possible to know if a friend is connected to facebook with a c# code ? I watched all methods , i don't find solution.
Thanks
Si tu aimes ce que tu fais , tu finis par réussir !
(french proverb of David Zenou)
|
|
|
|
|
I haven't written any facebook articles. If you want to speak to someone who wrote an article, use the forum provided under the article itself.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Christian Graus wrote: any facebook articles
Are there any submitted here on CP? Never really noticed it if there has been.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
He said ' I love your facebook articles' so I just assumed another guy who thinks CP is a sweatshop where the same people write the articles and work the forums.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Hmmm, just did a search on facebook api and 5 articles did pop up. The simple WPF facebook application one looks kind of interesting.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
here's my sample program in my addProducts..
if i click my save button.. when i run it, i prompts an error message that reader is closed.. can anyone help me?
private void btnSaveChangesObject_Click(object sender, EventArgs e)
{
try
{
clsPublic.objConn.Open();
OdbcCommand com = new OdbcCommand("Select Name from Products", clsPublic.objConn);
OdbcDataReader read;
read = com.ExecuteReader();
while (read.Read())
{
if (read[0].ToString() == txtprodname.Text)
{
MessageBox.Show("Error!");
}
else
try
{
String strSQL;
if (clsPublic.BoolUpdateProductsRec == true)
{
strSQL = "Update products Set Id = '" + txtprodId.Text +
"', Name = '" + txtprodname.Text +
"', Description = '" + txtdesc.Text +
"', Type = '" + txttype.Text +
"', Price = '" + txtprice.Text +
"', Brand = '" + txtbrand.Text +
"' where Id = '" + txtprodId.Text + "'";
}
else
{
strSQL = "Insert Into products Values('" + txtprodId.Text +
"', '" + txtprodname.Text +
"', '" + txtdesc.Text +
"', '" + txttype.Text +
"', '" + txtprice.Text +
"', '" + txtbrand.Text + "')";
}
SaveObjectRecord(strSQL);
btnCloseSaveChangesObject.PerformClick();
}
catch (NullReferenceException NRE)
{
MessageBox.Show("Error:" + NRE.Message, "ARTM", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
catch (NullReferenceException NRE)
{
MessageBox.Show("Error:" + NRE.Message, "ARTM", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
|
|
|
|
|
Looks messy. When do you get the error ? Which catch block is it in ?
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Christian Graus wrote: Looks messy.
Yes, it does. Not to mention the sql injection attack vulnerability
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
I've given up on pointing that out. People who hire teams who have no idea how to write secure code, deserve what they get.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Christian Graus wrote: given up on pointing that out
Same here. Used to point people towards Colin's article and some were grateful and others, well, they didn't really care ( at least until someone tosses a
'; drop database master; -- or some crap like that into the query string ).
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
I suppose that the SaveObjectRecord method closes the connection? Then you will get the error after saving a record when you try to continue to read the rest of the records.
Do you really indend to update/insert the same record over and over again, once for each record in the Products table? Or did you accidentally put the code that saves the record inside the loop instead of after the loop?
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
|
Hi guys,
I'm starting out with C# and since I dont like messing with simple things ( ) I'm already "playing" with threads and delegates. In my program I create a net socket, connect to a server and start to receive data async with BeginReceive.
When a message is received, the program(secondary thread of BeginReceive) pass it to RlsInsert(message) that split it with a regular expression and populate a listview. It seems to work perfectly but randomly VS pops up with an exception about NullReferenceException and tells me to use the "new" keyword, but as you can see I'm already using it:
//Add item to the list view
public delegate void RlsInsertCallback(string text);
public void RlsInsert(string text)
{
if (this.InvokeRequired)
this.Invoke(new RlsInsertCallback(this.RlsInsert),new object[] { text }); <--- expection on this line pointin to object[]
else
{
**more code that check text with regular expression, split text and populate subitems etc
lvRelease.Items.Add(aItem);
}
}
Can anybody tell me what I am doing wrong? Because I cant figure it out. It works and then It crashes after a while.
Sorry if this has already been asked, I did used search but I could not find anything that really match my problem.
Thank you in advance.
Matteo
|
|
|
|
|
Could this.RisInsert or text be null ?
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Thanks for replying.
I changed the code a bit includin a check for null text:
public void RlsInsert(string text)
{
if (text != null)
{
if (this.InvokeRequired)
this.Invoke(new RlsInsertCallback(ListAddItem), new object[] { text });
else
{
ListAddItem(text);
}
}
}
But I get the same error. Not sure about this.RlsInsert (ListAddItem: I put the code to populate the listview in another method) null or not. How can it be null?
|
|
|
|
|
I would do a try/catch and then check the values of the various variables when the catch occurs.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Ok I'm doing it right now, I'll let you know. Ty
|
|
|
|
|
I have 5 items in a listbox and am custom paiting each item. but if i click at the very bottom within the listbox i should be getting -1 but I always get the last item index.
private void listbox_MouseDown(object sender, MouseEventArgs e)
{
int indx = this.IndexFromPoint(e.X, e.Y);
MessageBox.Show(indx.ToString());-->>; I always get the last item index
}
I ran a simple test by adding a listbox on a form and on a mouse click if i click outside of the listitem i get -1. means no item is selcted.
Can somebody tell me where the problem os
|
|
|
|
|
What if you handle mouse up instead of down ? Perhaps the selection changes in mouse click, which fires between down and up.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|