I'm in work fighting with one bug which I can't google/solve. Our app has blocked landscape mode (it never change orientation), but while testing it I saw it crashes while being on different rotation (but still on portrait mode). Code working good well always on portrait mode. We have one activity which have ViewPager (with 3 fragments). App is crashing while trying to get getActivity (because its nullpointer).
In activity I'm opening method from fragment to fill some radio buttons information in runOnUiThread method:
@Override
public void onGetPlayerSuccess(HandballPlayerTO player) {
handballPlayer = player;
if (handballPlayer.gethandballDictionaryFacts() == null) {
handballPlayer.sethandballDictionaryFacts(new ArrayList<HandballDictionaryFactTO>());
}
setRefreshing(false);
injuriesAdapter.setInjuries(player.getHandballInjuryTOS());
injuriesAdapter.notifyDataSetChanged();
setListAppendixViews();
runOnUiThread(new Runnable() {
@Override
public void run() {
demographicFragment.fillFields();
careerFragment.fillFields();
lifestyleFragment.fillFields();
}
});
}
Inside fillField()
I'm using following method:
HandballPlayerTO player = ((PlayerActivity) getActivity()).getPlayerTO();
which crashes app, while I am trying just to send the player through arguments it doesn't have correct information.
I'm totally confused because I never heard about differences in running the code in landscape mode/portrait mode.
Both have same code, same XML. I don't change the orientation. I tried to run it from beginning on landscape (and it crashes) and change orientation from portrait mode before opening activity (and it crashes too).
I only can find solution to null pointer problem for issues on changing orientation etc.