0

I pretty much just have a canvas on my android app that has a text in the center of the screen (I tried a set position like 100,100 or like canvas.getWidth()/2, canvas.getHeight()/2) when the user switches the mode whether from portrait to landscape or from landscape to portrait during that switch it crashes and reports a null pointer exception. When nothing is drawn on the canvas I can freely switch between the two modes. How can I stop the crashing ?

Snipekiller430
  • 13
  • 1
  • 1
  • 4

1 Answers1

0

Add this attribute in Android manifest file, into activity tag

  android:configChanges="orientation"

Then may be your problem solve because when orientation is changing that time activity is restarting and all object having null reference..

Vishesh Chandra
  • 6,951
  • 6
  • 35
  • 38