- Jun 3, 2013
- 1
- 0
- 0
I am writing a windows phone 8 application. I am seeing the following error: A first chance exception of type 'System.OutOfMemoryException' occurred in System.Windows.ni.dll I have zoned the code that causes this error, but i am not able to fix it. Feel free to help me out here
Code:
public void getTheWholeChapter(string startbooknum, string startchapter)
{
System.Uri uri = new Uri("http://api.seek-first.com/v1/BibleSearch.php?type=lookup&appid=seekfirst&startbooknum=" + startbooknum + "&startchapter=" + startchapter + "&startverse=1&endbooknum=" + startbooknum + "&endchapter=" + startchapter + "&endverse=5000000&version=KJV");
WebClient client = new WebClient();
OpenReadCompletedEventHandler orceh = new OpenReadCompletedEventHandler(GetTheData);
client.OpenReadCompleted += orceh;
client.OpenReadAsync(uri);
}
private void GetTheData(object sender, OpenReadCompletedEventArgs e)
{
if (e.Error == null)
{
StreamReader reader = new StreamReader(e.Result);
string stringXML = reader.ReadToEnd().ToString();
ListBox tb = new ListBox();
//tb.IsGroupingEnabled = true;
//tb.HideEmptyGroups = true;
//tb.LayoutMode = LongListSelectorLayoutMode.List;
tb.FontSize = 25;
List<TextBlock> listOfVerses = new List<TextBlock>();
//get the deatails from the
if (stringXML != "" && stringXML != null)
{
XDocument root = XDocument.Parse("<Document>" + stringXML.Replace("></a>", "/></a>") + "</Document>");
var ResultsX = from Results in root.Descendants("Result")
select Results;
foreach (var Result in ResultsX)
{
listOfVerses.Add(new TextBlock()
{
Text = Result.Element("Chapter").Value + ":" + Result.Element("Verse").Value + " " + Result.Element("Text").Value,
TextWrapping = TextWrapping.Wrap,
});
}
}
tb.ItemsSource = listOfVerses;
((PivotItem)this.chaptersPivot.Items[chaptersPivot.SelectedIndex]).Content = tb;
}
else
{
//handle this
}
//throw new NotImplementedException();
}