0

i am making a windows 8 store blog reader application, and i am having trouble with navigating from the first page of my application to the second. The first page provides a list of items and on clicking one, you navigate to the second page which gives more information about the selected item based on its title. The code for doing this is as below.

    public static FeedData GetFeed(string title)
    { 
            // Simple linear search is acceptable for small data sets
            var _feedDataSource = App.Current.Resources["feedDataSource"] as FeedDataSource;

            var matches = _feedDataSource.Feeds.Where((feed) => feed.Title.Equals(title));
            if (matches.Count() == 1) return matches.First();
            return null;


    }

When i run the application i get the error NullReferenceWasUnhandledByUserCode. Object reference not set to an instance of an object. Can someone kindly give a workaround for this.

Dan Lowe
  • 51,713
  • 20
  • 123
  • 112
  • You return null your self...http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it – rene Sep 10 '14 at 12:34

2 Answers2

0

Some of the feed links are broken so the feed data that is returned contains some null feeds, parsing them causes this exception.

Change this line of code:

var matches = _feedDataSource.Feeds.Where((feed) => feed.Title.Equals(title));

to :

var matches = _feedDataSource.Feeds.Where((feed) => feed != null && feed.Title.Equals(title));

This will ignore those empty feeds.

0

The Windows Blog Reader App tutorial present in msdn documentation is quite out dated, and the feed links mentioned are also broken because microsoft changed the links of windows blogs from "windowsteamblog.com" to "blogs.windows.com"

I had been trying this tutorial recently, & unfortunately ran into a lot of errors, exceptions, etc. To solve the problem, I searched the web, & also found the shear no. of people who faced this problem. I also came across a channel9 blog, which had a list of channel9 blogs. So, i used those links & converted the Windows Blog Reader App to Channel9 Blog Reader App.

It's same as the Windows 8 Blog Reader, the main difference being the feed links changed from "windowsteamblog.com" or "blogs.windows.com" to "channel9.msdn.com".

And also there are a couple of minor changes as it is a Windows 8.1 app & not Windows 8 app, so it will be better if u read this article about migrating a Windows 8 app to Windows 8.1 app :- migrating a Win 8 app to Win 8.1 app

Here is the link to the source code of the app :- Channel9 Blog Reader App Source Code