I am working on a game where the player can drag and drop things around the screen. I\'ve got a private method which allows me to simulate a drag/drop event for any of the i
Can you try this, to ensure that simulateMovingImg is present
if (myLayout.indexOfChild() >= 0)
{
myLayout.removeView(simulateMovingImg);
}
I met this issue after I updated the appcompat-v7. The latest stable version of the above-mentioned dependency to now is:
compile 'com.android.support:appcompat-v7:23.2.1'
I slightly changed an accepted answer (it also works) to avoid handlers.
@Override
public void onAnimationEnd(Animation animation) {
imageView.post(new Runnable() {
@Override
public void run() {
layout.removeView(imageView);
}
});
}
Android will make an exception when you change the view hierarchy in animationEnd.
All you have to do is to postpone your call like this :
@Override
public void onAnimationEnd(Animation animation) {
new Handler().post(new Runnable() {
public void run() {
myLayout.removeView(simulateMovingImg);
}
});
}
My guess is that it is a multi threading problem. It looks like the internal android render loop is encountering a null pointer due to the fact that you removed the image from another thread. The Android UI framework is single threaded and all modifications to the UI must happen in the UI thread. If this is the problem you are encountering then you can just delegate your call to the UI thread.
There is some related information here: android threading