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?
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.