Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7851899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:17:26+00:00 2026-06-02T19:17:26+00:00

I am getting a null reference exception while trying to navigate back to the

  • 0

I am getting a null reference exception while trying to navigate back to the pervious MainPage.xaml using the below code from my RSS reader. Can someone please help me by advising what I need to do to avoide this error?

public partial class FeedDetailsPage : PhoneApplicationPage
{
    object _selectedFeedItem;
    object _selectedFeed;

    public FeedDetailsPage()
    {
        InitializeComponent();
        Loaded += new RoutedEventHandler(PhoneApplicationPage_Loaded);
        LoadFeed();
    }

    private void LoadFeed()
    {
        FrameworkElement root = Application.Current.RootVisual as FrameworkElement;
        var currentFeed = root.DataContext as ATP_Tennis_App.ViewModels.FeedViewModel;
        WebClient wc = new WebClient();
        wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);
        wc.DownloadStringAsync(new Uri(currentFeed.FeedUrl));
        _selectedFeed = currentFeed;
    }

    void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
    {
      //  if (e.Error != null) { return; }

        var rssFeed = XElement.Parse(e.Result);

        var currentFeed = this.DataContext as ATP_Tennis_App.ViewModels.FeedViewModel;
        var items = from item in rssFeed.Descendants("item")

                    select new ATP_Tennis_App.ViewModels.FeedItemViewModel()
                    {

                        Title = item.Element("title").Value,
                        DatePublished = DateTime.Parse(item.Element("pubDate").Value),
                        Url = item.Element("link").Value,
                        Description = item.Element("description").Value
                    };
        foreach (var item in items)
            currentFeed.Items.Add(item);

    }

    private void PhoneApplicationPage_BackKeyPress(object sender, System.ComponentModel.CancelEventArgs e)
    {
        // Cancel default navigation

        e.Cancel = true;
        PhoneApplicationFrame root = (PhoneApplicationFrame)Application.Current.RootVisual;
        root.GoBack();



    }


    private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
    {
        this.DataContext = _selectedFeed;
    }



    private void lstFeeds_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        _selectedFeedItem = (sender as ListBox).SelectedItem;
        NavigationService.Navigate(new Uri("/FeedItemDetailsPage.xaml", UriKind.Relative));
        FrameworkElement root = Application.Current.RootVisual as FrameworkElement;
        root.DataContext = _selectedFeedItem;
    }


}

the exception is thrown on line

wc.DownloadStringAsync(new Uri(currentFeed.FeedUrl));
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T19:17:28+00:00Added an answer on June 2, 2026 at 7:17 pm

    I have resolved this. The error was in my MainPage script. I have moved the datacontext setting into the main script and now the error is no longer thrown

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting null-exception throw error in the following code. What can be the
IN JAVA CODE IN JSP as below i m getting null value for fieldnoOfRecords.
Hi i am reading inbox using service but i m getting null pointer exception
I'm Getting a Null Pointer Exception while canceling the Progress Dialog in Async Task
I keep getting a null exception at the ; below. The ApiUsername & ApiPassword
I am learning WCF and right now I am getting one exception while running
I'm trying to debug a third party library that is throwing an null reference
I'm getting a Null pointer access: The variable 'numbers' can only be null at
I am trying to play the selected media from PlayList,if the selected index is
I'm interested in properly handling Faults within a WCF REST Service client. While using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.