0

I want to build a RSS Reader but I am getting a 'cannot resolve symbol' error in my onStart Method at mRssFeed.setText(rssFeed) where it has a problem with the mRssFeed. Here is my whole class:

@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();
            }
        }
    }
}

Can someone please help me with this?

Lukas Schröder
  • 344
  • 1
  • 2
  • 16
  • Possible duplicate of [What is the difference between a local variable, an instance field, an input parameter, and a class field?](http://stackoverflow.com/questions/20671008/what-is-the-difference-between-a-local-variable-an-instance-field-an-input-par) – Murat Karagöz Feb 10 '17 at 14:54

1 Answers1

2

The variable mRSSfeed is declared inside onCreateView so onStart cannot access it.

Declare it outside the method inside the Class instead like this

TextView mRssFeed;

Then in onCreateView change the line to

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

Carl Poole
  • 1,970
  • 2
  • 23
  • 28