Hi,
I am trying to use the Bing API to retrieve the first image on whatever search query I enter and then strore the url of the image in MySQL. I am nearly there with it but I am getting an error which I am unable to fix.
The above code is run about 400 times through all the movie titles.
Although I keep getting the error on the purple line above:
Code
Object reference not set to an instance of an object.
I am still quite new to C# but I am thinking that it is running through the movies so quickly that the Bing API is unable to keep up with getting the images?
Someone can tell me if I am way off base..
Can someone point me in the right direction?
Thanks
Jay
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Bryian TanRank #396 · 6.3K reputationPosted Jan 31, 2011, 7:53 PM EST
0
hello,
Did you check/debug if the response is null? or the response.Image.Results[0] is null?
Jay Webster58 reputationPosted Jan 31, 2011, 10:05 PM EST
0
I tested to see if it was null by doing the following:
if (response.Image.Results[0].MediaUrl == null) { Console.Writeline("Null"); } else { OdbcCom.Parameters.Add("@db_image", OdbcType.Text).Value = response.Image.Results[0].MediaUrl; }
It still throws the error. Maybe I am doing it wrong?
Jay
Bryian TanRank #396 · 6.3K reputationPosted Jan 31, 2011, 7:53 PM EST
Did you check/debug if the response is null? or the response.Image.Results[0] is null?
Jay Webster58 reputationPosted Jan 31, 2011, 10:05 PM EST
if (response.Image.Results[0].MediaUrl == null)
{
Console.Writeline("Null");
}
else
{
OdbcCom.Parameters.Add("@db_image", OdbcType.Text).Value = response.Image.Results[0].MediaUrl;
}
It still throws the error. Maybe I am doing it wrong?
Jay