After defining our variables, it is also essential to initialize them. We do so from our surfaceCreated() method as follows:
@Overridepublic void surfaceCreated(SurfaceHolder holder){ bgImg = new BackgroundImage(BitmapFactory.decodeResource (getResources(), R.drawable.background_image)); playerCharacter = new PlayerCharacter(BitmapFactory.decodeResource (getResources(),R.drawable.player_run),200,246,3); rocks = new ArrayList<Rock>(); rockStartTime = System.nanoTime(); //we can safely start the game loop mainThread.setRunning(true); mainThread.start();}
And that takes care of our variable values.