It looks like the error is coming from tv, not BlueToothChat.potato. Have you initialized the "tv" variable at that point in the code?
Using variables in one class in another class NullpointerException - RunTimeException
-
28-06-2023 - |
Frage
I tried to do something extremely simple or I thought it was.
In my BluetoothChat, I set
public static boolean potato = false;
In the onCreateBundle of my MainActivity, I have
if(BluetoothChat.potato == false)
{
tv.setText("it did not crash");
}
My application crashes immediately upon me switching windows from bluetoothchat to mainactivity. I receive java.lang.RuntimeException and java.lang.NullPointerException. However, the application does not crash and switches perfectly if I have the if statement commented out.
Lösung
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow