-
August 4th, 2012, 07:47 AM
#1
Question on debug error
Hey guy, not sure if my last post got here, my internet is going in and out... Thanks TWC
Hopefully this isnt a double post...
Getting this error while debugging
NULLReferenceExceptionOccured
Not sure why, here is the code;
Code:
public void LogOnToEmross()
{
try
{
HttpWebRequest requestEvents = WebRequest.Create(string.Concat(new object[] { this.server.server, "game/get_cdinfo_api.php?key=", this.userkey.key, "&city=", this.userinfo.user.city[0].id, "&_l=en" })) as HttpWebRequest;
using (HttpWebResponse response = requestEvents.GetResponse() as HttpWebResponse)
{
StreamReader reader = new StreamReader(response.GetResponseStream());
if (reader.ReadToEnd().Contains("code:0"))
{
HttpWebRequest requestEvents2 = WebRequest.Create(this.server.server + "game/get_userinfo_api.php?key=" + this.userkey.key + "&_l=en") as HttpWebRequest;
using (HttpWebResponse response2 = requestEvents2.GetResponse() as HttpWebResponse)
{
string responseText = new StreamReader(response2.GetResponseStream()).ReadToEnd();
string[] seperator2 = new string[] { "\"ret\":" };
string[] temp2 = responseText.Split(seperator2, StringSplitOptions.None);
UserInfo testResult = Json.Deserialize<UserInfo>(temp2[1].Substring(0, temp2[1].Length - 3).TrimEnd(this.trimmer).TrimStart(this.trimmer));
this.userinfo = testResult;
}
this.GetChestsAndKeys();
}
else
{
this.LogOn();
this.GetChestsAndKeys();
}
}
}
catch
{
this.LogOn();
this.GetChestsAndKeys();
}
}
Last edited by DataMiser; August 4th, 2012 at 10:15 AM.
Reason: added code tags
-
August 5th, 2012, 02:08 PM
#2
Re: Question on debug error
To make answering this simpler, a debugger should be able to tell you exactly what line the exception occurred at. Most debuggers can even break on exception allowing for you to take a look at the state of objects at the time of the exception.
Personally, I use Visual Studio and when I get a null ref exception (not from code i wrote of course ) I'll make sure "throw" for null ref exception is checked in the "Debug->Exceptions..." dialog. Then when the application breaks, I'll hover over variables on the line until I find the one that is null & shouldn't be, then I'll backtrack to find out why its null.
Hope this helps...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|