I’ve set the manifest entry for my Activity so that it handles orientation changes by itself.
In my onConfigurationChanged(), I’ve got this:
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
findViewById(R.id.header).post(new Runnable() {
@Override
public void run() {
}
});
}
After months of working without problems, I’ve just had a NullPointerException on the findViewById() line. My conclusion is that the View in question hasn’t been created yet, due to the omission of setContentView().
Is setContentView() really necessary here? If so, why has it been working all this time without incident?
No, calling
setContentViewis not necessary in that situation. Something else in your code is causing thefindVieWByIdto return null.