Null check as @Shynthriir has mentioned is the simplest most efficient way (AFAIK) to get around the problem.
I would however strongly recommend initiating strings to an empty string String str = ""; instead, which would save you a lot of headache in a more complex programming effort.