I am surprised myself that I am writing such a question. I already broke my head, probably somewhere I missed something.

Here it is, everyone knows:

String str = "ΠΊΠ°ΠΊΠΎΠΉ-Ρ‚ΠΎ ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€"; 

But if I do it like this:

  public class БАБАБА { String str; protected void Π›ΡŽΠ±ΠΎΠΉ ΠΌΠ΅Ρ‚ΠΎΠ΄ { ...ΠΊΠ°ΠΊΠΎΠΉ-Ρ‚ΠΎ ΠΊΠΎΠ΄ ΠΈ ΠΏΠΎΡ‚ΠΎΠΌ Π³Π΄Π΅-Ρ‚ΠΎ str = dataSnapshot.getValue().toString(); // - ΠΏΡ€ΠΈΠ΅ΠΌ string с firebase 

That str is not assigned a value transmitted from the server, but remains null.

Maybe you need to somehow assign a different way, in some magical way? Maybe I missed something somewhere according to science.

Because of this, doing such a trick:

  public class БАБАБА { String str; TextView textView; protected void Π›ΡŽΠ±ΠΎΠΉ ΠΌΠ΅Ρ‚ΠΎΠ΄ { ...ΠΊΠ°ΠΊΠΎΠΉ-Ρ‚ΠΎ ΠΊΠΎΠ΄ ΠΈ ΠΏΠΎΡ‚ΠΎΠΌ Π³Π΄Π΅-Ρ‚ΠΎ str = textView.setText(dataSnapshot.getValue().toString()); // - ΠΏΡ€ΠΈΠ΅ΠΌ string с firebase 

Help please advice.

  • one
    Try to cast the resulting value to the String type with this method str = (String) dataSnapshot.getValue() - qwerty123
  • there is such an interesting moment. I did it in another part of the program and everything worked. Along the way, somewhere in my head a joint)) - Andrey
  • Is str set to null or does NullPointerException crash? Here: str = dataSnapshot.getValue().toString(); // - ΠΏΡ€ΠΈΠ΅ΠΌ string с firebase str = dataSnapshot.getValue().toString(); // - ΠΏΡ€ΠΈΠ΅ΠΌ string с firebase . - Tema_Bel
  • Nah, just null and all - Andrey
  • And what type of getValue() returns? - Tema_Bel

1 answer 1

Must save String.valueOf(...)