###前提・実現したいこと
http://t-quruli.hatenadiary.jp/entry/2016/09/03/113708
ここのサイト様のようにニコニコニュースをUnityで取得しようとしてるのですが、エラーメッセージがでてしまいました。
###発生している問題・エラーメッセージ
NullReferenceException: Object reference not set to an instance of an object RSSpro+<GetNews>c__Iterator1.MoveNext () (at Assets/RSSpro.cs:38) UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)
###該当のソースコード
C#
1using UnityEngine; 2using System.Collections; 3using System.Collections.Generic; 4using UnityEngine.UI; 5using MiniJSON; 6 7public class RSSpro: MonoBehaviour { 8 9 10 public GameObject itemPrefab = null; 11 public GameObject parent = null; 12 13 14 15 private string nikonikoNews = "https://ajax.googleapis.com/ajax/services/feed/load?v=1.0&q=http://news.nicovideo.jp/topiclist?rss=2.0"; 16 17 18 // Use this for initialization 19 private IEnumerator Start () { 20 21 22 23 yield return GetNews( nikonikoNews ); 24 25 26 } 27 28 29 private IEnumerator GetNews ( string url ) 30 { 31 WWW www = new WWW( url ); 32 33 34 yield return www; 35 36 var data = (Dictionary<string,object>)MiniJSON.Json.Deserialize( www.text ); 37 var responce = (Dictionary<string,object>)data[ "responseData" ]; 38 var feed = (Dictionary<string,object>)responce[ "feed" ]; 39 var entries = (List<object>)feed[ "entries" ]; 40 41 for ( int i = 0; i < entries.Count; i++ ) 42 { 43 var list = ( Dictionary<string, object> )entries[ i ]; 44 45 GameObject obj = Instantiate( itemPrefab ); 46 Text text = obj.GetComponentInChildren<Text>(); 47 text.text = (string)list[ "title" ]; 48 49 50 obj.transform.parent = parent.transform; 51 52 } 53 54 } 55} 56
###試したこと
NullReferenceExceptionが設定されていない変数を示しているときに出るエラーということは理解できたのですが、具体的にどのように解決したら良いのかがわからず困っています。
回答よろしければお願いいたします。
###補足情報(言語/FW/ツール等のバージョンなど)
unity 2017.1.1f1
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/01/16 17:47