I have multiple ImageViews on my screen. Whenever the user moves his finger over one or multiple of them, I want the ones the finger touched, to be removed and create new ImageViews.
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
((ViewGroup) view.getParent()).removeView(view);
createNewImageViews();
return true;
}
The problem is, that my app crashes. I think the reason is, that a touchlistener is called again, that already deleted its view and tries to delete it again.
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.ViewGroup.removeView(android.view.View)' on a null object reference
What should I do to make it working properly?