Answer the question
In order to leave comments, you need to log in
Android Fragments. Why get NullPointerException in some cases?
The bottom line is, I have two versions of the code, which in my opinion should do the same thing. But in one of the versions NullPointerException is obtained.
What am I trying to do?
I need to get the data entered into the EditText, the EditText is in a fragment.
The code below works.
Answer the question
In order to leave comments, you need to log in
You're not working with fragments correctly.
As I understand it, this textview, where you are trying to set the text, is in a fragment. Don't do that, it breaks encapsulation. Only the fragment itself should change its views.
Further, the commit occurs asynchronously. And the fact that you are trying, as it were, to do something between the start of the transaction and the commit, obviously hoping that it will fall into the transaction, is wrong. Transactions are for fragments only.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question