Hi
When ran my code in the emulator and i clicked a button it shows the following error "An unhandled exception of type 'System.StackOverflowException' occurred in Unknown Module."
Kindly help proffer a solution
Thank you inadvance
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Jan 21, 2015, 5:43 PM
JOHN JOHNNNYPosted Jan 21, 2015, 6:23 PM
JOHN JOHNNNYPosted Jan 21, 2015, 4:57 PM
This is my code below
public partial class BibleInYear
{
public string Date { get; set; }
[JsonProperty("Bible Chapter")]
public string BibleChapter { get; set; }
[JsonProperty("Bible Content")]
public string BibleContent { get; set; }
public override string ToString()
{
string[] props = new string[3];
props[0] = "DATE - " + Date;
props[1] = "Bible Chapter - " + BibleChapter;
props[2] = "Bible Content - " + BibleContent;
return String.Join("\r\n\r\n", props);
}
}
xaml.cs
public partial class BibleInYear : PhoneApplicationPage
{
private List
public BibleInYear()
{
InitializeComponent();
devotions = new List
AddDevotions();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
DateTime dt = DateTime.Now;
int month = dt.Month;
int year = dt.Year;
int index;
if (DateTime.IsLeapYear(year) || (month <= 2))
{
index = dt.DayOfYear - 1; // list is indexed from 0
}
else
{
index = dt.DayOfYear; // add a day
}
textblock.Text = devotions[index].ToString(); // or some other property
}
private void AddDevotions()
{
for (int i = 1; i <= 366; i++)
{
string filePath = "MyDevotions/Devotion" + i.ToString() + ".json";
BibleInYear d = ReadJsonFile(filePath);
devotions.Add(d);
}
}
public BibleInYear ReadJsonFile(string JsonfilePath)
{
BibleInYear[] d = null;
using (StreamReader r = new StreamReader(JsonfilePath))
{
string json = r.ReadToEnd();
d = JsonConvert.DeserializeObject
}
return d[0];
}
Await your reply
VulpesPosted Jan 21, 2015, 4:29 PM
It can also occur if a class definition contains a field with the same type as itself. In such a case the constructor keeps on calling itself until the stack overflows.
However, to diagnose and fix the problem, you need to be able to pinpoint where in your code it's happening. So I'd use the debugger to find out where the error is occurring and, if you can't see anything obvious yourself, post the code here so we can have a look at it.