2017-02-10 21 views
0

RSSリーダーを作成したいのですが、私のonStartメソッドで「シンボルを解決できません」というエラーが発生しましたmRssFeed.setText(rssFeed)ここでは、mRssFeedに問題があります。ここに私のクラス全体があります:setTextでシンボルを解決できません

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
    View rootView = inflater.inflate(R.layout.feed_fragment_portrait, container, false); 
    TextView mRssFeed = (TextView) rootView.findViewById(R.id.rss_feed); 
    return rootView; 
} 
@Override 
public void onStart() { 
    super.onStart(); 
    InputStream in = null; 
    try { 
     URL url = new URL("http://www.androidpit.com/feed/main.xml"); 
     HttpURLConnection conn = (HttpURLConnection) url.openConnection(); 
     in = conn.getInputStream(); 
     ByteArrayOutputStream out = new ByteArrayOutputStream(); 
     byte[] buffer = new byte[1024]; 
     for (int count; (count = in.read(buffer)) != -1;) { 
      out.write(buffer, 0, count); 
     } 
     byte[] response = out.toByteArray(); 
     String rssFeed = new String(response, "UTF-8"); 
     mRssFeed.setText(rssFeed); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } finally { 
     if (in != null) { 
      try { 
       in.close(); 
      } catch (IOException e) { 
       e.printStackTrace(); 
      } 
     } 
    } 
} 

誰か助けてもらえますか?

+0

可能性のある重複した[ローカルの違いは何であるにonCreateView変更して、代わりにこの

TextView mRssFeed;

ようなクラス内のメソッドの外にラインを、それを宣言します変数、インスタンスフィールド、入力パラメータ、およびクラスフィールド?](http://stackoverflow.com/questions/20671008/what-is-the-difference-between-a-local-variable-an-instance -field-an-input-par) –

答えて

2

mRSSfeedonCreateViewの中にあるので、onStartはアクセスできません。

はの

mRssFeed = (TextView) rootView.findViewById(R.id.rss_feed);

+0

ありがとう、これは私のために働いた。 –

関連する問題