S
S
Slavik122020-07-09 23:28:35
Android
Slavik12, 2020-07-09 23:28:35

Why does an android app crash after adding text.setText("dgds")?

There is an application. At some point, I want to completely replace the current activity with another one. I implemented it like this:

llRepetition.removeAllViews();
tvWord_ROWW = (TextView) findViewById(R.id.tvWord_ROWW);
LayoutInflater ltInflater = getLayoutInflater();
View view = ltInflater.inflate(R.layout.activity_repetition_of_words_writing, llRepetition, true);
ViewGroup.LayoutParams lp = view.getLayoutParams();
tvWord_ROWW.setText("word");
llRepetition.addView(tvWord_ROWW);

and if you remove the last two lines, then the replacement goes well and a new activity appears, but when I start playing with the view elements, the application crashes. Maybe I’m not implementing the replacement of the activity in the same way at all, and here it’s necessary somehow differently? Point me in the right direction please

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2020-07-09
@Slavik12

You have null in tvWord_ROWW because you are assigning/looking for it before adding it.
In general, they don’t usually do this, it’s not very clear what you are trying to achieve with these dances. If they are different screens, use fragments. You don't replace activities, you only change views.
Use normal names: camelCase. Don't mix it with snake_case. Do not use Hungarian notation, in Java and Android this is usually not accepted.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question