Abhishek Tandon Abhishek Tandon - 4 months ago 21
Android Question

SwipeReferesh is not working in Android

I am working on a app and when I apply following code it shows errors in second line,


NullPointerException


swipeRefreshLayout=(SwipeRefreshLayout)rootView.findViewById(R.id.swipereferesh);
swipeRefreshLayout.setOnRefreshListener(
new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
getNewsPosts(true);
}
}
);


What could be the issue?

Answer

You might have forgotten to add SwipeRefreshLayout tag in your layout file or may be you forget to initialize it before calling setOnRefreshListener to it.

If this will not fix your problem add your layout file and code there.