-1

I have got error Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference and it is caused by my onResume() method which runs twice.

MainFragment which is containing few tabs caused it.

Why? Any idea?

Thanks for help.

y07k2
  • 1,898
  • 4
  • 20
  • 36

1 Answers1

0

If onResume is being called twice then onCreate and onStart are being called again or onPause is being called between the 2 onResume calls. If you find which one of these possibilities it is it will provide a clue as to what is happening. You can find them by putting a break point in the 3 methods.

There are multiple reasons why one of these possibilities might be happening and without seeing more details (the fragment/activity code, AndroidManifest, user behaviour) I will just have to list some of them.

  1. Another activity is being started and then ends. This could be an activity you don't see such as one requesting use of a resource.
  2. The device is rotated (along with onCreate and onStart)
  3. The activity/fragment is being relaunched from somewhere else.

Please provide more code if my answer doesn't help.

rogermushroom
  • 5,486
  • 4
  • 42
  • 68