I am getting a null pointer exception in the line given in code below. The problem is, the exception occurs randomly. Many times it just works but sometimes it throws an exception (say 5% of times). Any help would be appreciated.
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
Animation animation = AnimationUtils.loadAnimation(getActivity().getApplicationContext(), R.anim.dialog_main_show_amination); //Exception in this line
fabAddDeliveryBoy.startAnimation(animation);
fabAddDeliveryBoy.setVisibility(View.VISIBLE);
}
}, 500);