My program runs perfectly well when starting in any rotation/orientation, but when I change the orientation between landscape<->portrait while it's running, I get a null pointer exception because of my canvas.
@Override
public void run(){
    while(running){
        if(surfaceHolder.getSurface().isValid()){
            Canvas canvas = surfaceHolder.lockCanvas();
            canvas.drawColor(Color.BLACK); //NULLPOINTEREXCEPTION here
            paint(canvas); //another function of mine
            surfaceHolder.unlockCanvasAndPost(canvas);
        }
    }
}
And I have android:configChanges="orientation" in my manifest as well as
@Override
public void onConfigurationChanged(Configuration newConfig){
    super.onConfigurationChanged(newConfig);
    setContentView(R.layout.main);
}
When I comment out canvas.drawColor(Color.BLACK), paint(canvas) gets called and then the null pointer exception happens the next time canvas is used in that function.
Help?
 
     
     
    