In an existing Android project I\'ve encountered the following piece of code (where I inserted the debugging litter)
ImageView img = null;
public void onCre
If you look at the docs for View.post there's some relevant info:
This method can be invoked from outside of the UI thread only when this View is attached to a window.
Since you're doing this in onCreate, it is likely that sometimes your View will not be attached to the window yet. You can verify this by overriding onAttachedToWindow and putting something in the logs and also logging when you post. You'll see that when the post fails, the post call happens before onAttachedToWindow.
As the others have mentioned, you can use Activity.runOnUiThread or provide your own handler. However, if you want to do it directly from the View itself, you can simply get the View's handler:
view.getHandler().post(...);
This is especially useful if you have a custom view that includes some sort of background loading. There's also the added bonus of not having to create a new separate handler.