App Crashes after Rotation with setText


#1

Hey,
when I add this lines of code:

mApiLevel = (TextView) findViewById(R.id.api_level_text_view); mApiLevel.setText("API Level " + String.valueOf(Build.VERSION.SDK_INT));

My application works fine when the first OnCreate is generated.
But when I rotate the device and the OnCreate regenerates, I get a crash.

At first I tried this code as well, but it had the same problam:

mApiLevel = (TextView) findViewById(R.id.api_level_text_view); Resources res = getResources(); API_LEVEL = String.format(res.getString(R.string.api_level), Build.VERSION.SDK_INT); mApiLevel.setText("API Level " + String.valueOf(Build.VERSION.SDK_INT));

When I removed this lines, the rotation works fine.

I know that the setText is the reason I crash, but I don’t know why.

Does someone know why I get a NullPointerException?

Thanks.


#2

Hey,
I forgot to add a textview to the land layout… :smiley:


#3

Hi Jobi22,

I’m problably having the same problem right now… I have a loop with an interval of 6 seconds to retrieve data from a webservice. It is updated with settext, but when I rotate my screen the app crashes.
I can’t figure out where to try your solution. Could you please give me a bit more info?