Я пытаюсь реализовать RSS-канал в своем приложении.Я взял этот код с сайта.Я получаю Java.lang.NullPointerException рядом с методом execute внутри слушателя щелчка кнопки и проведите слушателя обновления.Мое приложение не запускается;он просто выдает ошибку в телефоне Android.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mRecyclerView = (RecyclerView)
findViewById(R.id.recyclerView);
mEditText = (EditText)
findViewById(R.id.rssFeedEditText);
mFetchFeedButton = (Button)
findViewById(R.id.fetchFeedButton);
mSwipeLayout = (SwipeRefreshLayout)
findViewById(R.id.swipeRefreshLayout);
mFeedTitleTextView = (TextView)
findViewById(R.id.feedTitle);
mFeedDescriptionTextView = (TextView)
findViewById(R.id.feedDescription);
mFeedLinkTextView = (TextView)
findViewById(R.id.feedLink);
mRecyclerView.setLayoutManager(new
LinearLayoutManager(this));
mFetchFeedButton.setOnClickListener(new
View.OnClickListener() {
@Override
public void onClick(View view) {
new FetchFeedTask().execute((Void) null);
}
});
mSwipeLayout.setOnRefreshListener(new
SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
new FetchFeedTask().execute((Void) null);
}
});
}
}
// FetchFeedTask class
private class FetchFeedTask extends AsyncTask<Void,
Void, Boolean> {
private String urlLink;
@Override
protected void onPreExecute() {
mSwipeLayout.setRefreshing(true);
urlLink = mEditText.getText().toString();
}
@Override
protected Boolean doInBackground(Void... voids) {
if (TextUtils.isEmpty(urlLink))
return false;
try {
if(!urlLink.startsWith("http://") &&
!urlLink.startsWith("https://"))
urlLink = "http://" + urlLink;
URL url = new URL(urlLink);
InputStream inputStream =
url.openConnection().getInputStream();
mFeedModelList = parseFeed(inputStream);
return true;
} catch (IOException e) {
Log.e(TAG, "Error", e);
} catch (XmlPullParserException e) {
Log.e(TAG, "Error", e);
}
return false;
}
@Override
protected void onPostExecute(Boolean success) {
mSwipeLayout.setRefreshing(false);
if (success) {
mFeedTitleTextView.setText("Feed Title: " +
mFeedTitle);
mFeedDescriptionTextView.setText("Feed
Description: " + mFeedDescription);
mFeedLinkTextView.setText("Feed Link: " +
mFeedLink);
// Fill RecyclerView
mRecyclerView.setAdapter(new
RssFeedListAdapter(mFeedModelList));
} else {
Toast.makeText(MainActivity.this,
"Enter a valid Rss feed url",
Toast.LENGTH_LONG).show();
}
}
}