i am unable to add to the observablecollection list. variables are retrieved and are also stored in the class instance but i am not able to add that instance to the list
Nullreference exception found at the line : await meth(); in LoadedData method
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using News_Specific.Resources;
using System.ComponentModel;
using System.Collections.ObjectModel;
//using System.ComponentModel;
//using News_Specific.Resources;
namespace News_Specific.ViewModels
{
public class Search
{
IndRes singleres = new IndRes();
IndResGrp singleresgrp = new IndResGrp();
//ObservableCollection<List<IndRes>> lst = new ObservableCollection<List<IndRes>>();
//public Result res;
public IndRes getresultitems{ get; set; }
public bool IsDataLoaded { get; set; }
public async void LoadData()
{
await meth();
}
public async Task<List<IndRes>> meth()
{
HttpClient client = new HttpClient();
string key = "s8w8MsPnqPUpcBHCn6ok0evbZGI_";
string topic = "windows";
string baseUrl = "http://www.faroo.com/api?" +
"q={0}" +
"&start=1" +
"&key={1}" +
"&length=2" +
"&l=en" +
"&src=news" +
"&f=json";
string url = string.Format(baseUrl,
topic,
key);
string result = await client.GetStringAsync(url);
RootObject obj = JsonConvert.DeserializeObject<RootObject>(result);
if (obj.results != null)
{
foreach (Result res in obj.results)
{
singleres.title = res.title;
singleres.kwic = res.kwic;
singleresgrp.Items.Add(singleres);
}
}
this.IsDataLoaded = true;
return singleresgrp.Items;
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (null != handler)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}
}