-1

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.

Kinjal
  • 1,195
  • 4
  • 13
  • 24
Jakub Anioła
  • 310
  • 3
  • 16
  • make sure this happens after onAttach in fragment. If it happens before or that fragment is not attached to activity this will fail – Cyph3rCod3r Feb 23 '17 at 10:54

1 Answers1

0

Solution which helped: Lock screen orientation (Android)

I changed manifest file, add screenOrientation to portrait mode. Previously we used flags while starting new activity.

Community
  • 1
  • 1
Jakub Anioła
  • 310
  • 3
  • 16