-1
observablecollection 목록에 추가 할 수 없습니다. 변수가 검색되어 클래스 인스턴스에도 저장되지만 해당 인스턴스를 목록에 추가 할 수 없습니다.null 참조 예외가 발생했습니다 ... 도와주세요.
Nullreference 예외가 다음 줄에서 발견되었습니다. await meth(); LoadedData 방법에 은
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));
}
}
}
}
안녕하세요, 그는 그냥 초보자이며 그를 도우려고 노력하고 있습니다. 그러면 자신의 ans를 해결 한 후 사용자가 직접 질문을 삭제하길 바랍니다. – loop