title: How to fix Null can not be a value of a non-null type in android maze game with Kotlin
body: <p>I was following a this tutorial to create a maze in android but im getting an error when i return null in the getNeighbour method</p>
  
  <p>error: Null can not be a value of a non-null type Cell</p>
  
  <p>Any help on what i am doing wrong its appreciated.</p>
  
  <p>I tried with Cell? but couldn't make it work, it gives me more errors</p>
  
  <p>Here is my code:</p>
  
  <pre><code>class GameView: View{
  //revisar por que hace cosas raras con los limites de cols y rows
  private val COLS:Int = 7
  private val ROWS: Int = 12
  private var cellSize: Float = 0F
  private var hMargin: Float = 0F
  private var vMargin: Float = 0F
  private val wallPaint = Paint()
  private val random:Random = Random()
  
  constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs){
      wallPaint.color = Color.WHITE
      wallPaint.strokeWidth = 1F
      createMaze()
  
  }
  fun getNeighbour(cell:Cell): Cell {
      var vecinos: ArrayList&lt;Cell&gt; = ArrayList()
  
      //vecino izquierda
      if(cell.col &gt; 0) {
          if (!cells[cell.col - 1][cell.row].visited) {
              vecinos.add(cells[cell.col - 1][cell.row])
          }
      }
      //vecino derecha
      if(cell.col &lt; COLS - 1) {
          if (!cells[cell.col + 1][cell.row].visited) {
              vecinos.add(cells[cell.col + 1][cell.row])
          }
      }
      //vecino arriba
      if(cell.row &gt; 0) {
          if (!cells[cell.col][cell.row - 1].visited) {
              vecinos.add(cells[cell.col ][cell.row - 1])
          }
      }
      //vecino abajo
      if(cell.row &lt; ROWS - 1) {
          if (!cells[cell.col][cell.row + 1].visited) {
              vecinos.add(cells[cell.col][cell.row + 1])
          }
      }
      if (vecinos.size &gt; 0) {
          var index = random.nextInt(vecinos.size)
          return vecinos[index]
      }else {
  
   // i get this error: Null can not be a value of a non-null type 
   // Cell
          return null
      }
  }
  
  fun removeWall(current:Cell,next:Cell){
      if (current.col == next.col &amp;&amp; current.row == next.row +1){
          current.topWall = false
          next.bottomWall = false
      }
      if (current.col == next.col &amp;&amp; current.row == next.row -1){
          current.bottomWall = false
          next.topWall = false
      }
      if (current.col == next.col + 1 &amp;&amp; current.row == next.row){
          current.leftWall = false
          next.rightWall = false
      }
      if (current.col == next.col - 1 &amp;&amp; current.row == next.row +1){
          current.rightWall = false
          next.leftWall = false
      }
  }
  
  var cells: Array&lt;Array&lt;Cell&gt;&gt;  = Array(COLS, {Array(ROWS, {Cell()})})
  
  fun createMaze(){
      var stack = Stack&lt;Cell&gt;()
      var current:Cell
      var next:Cell
  
      for(x in 0 until COLS){
          for(y in 0 until ROWS){
              cells[x][y] = Cell(x,y)
          }
      }
      current = cells[0][0]
      current.visited = true
  
      do{
          next = getNeighbour(current)
          removeWall(current,next)
          stack.push(current)
          current = next
          current.visited = true
  
      }while (!stack.empty())
  
  }
  override fun onDraw(canvas: Canvas) {
      canvas.drawColor(Color.DKGRAY)
      val ancho = width
      val alto = height
      println(ancho)
      println(alto)
      if(ancho/alto &lt; COLS/ROWS){
          cellSize = ancho/(COLS+1).toFloat()
      }else{
          cellSize = alto/(ROWS+1).toFloat()
  
      }
      hMargin = (ancho - COLS*cellSize)/2
      vMargin = ((alto - ROWS*cellSize)/2)
  
      canvas.translate(hMargin,vMargin)
  
      for(x in 0 until COLS){
          for(y in 0 until ROWS){
              if (cells[x][y].topWall){
              canvas.drawLine(
                  x*cellSize,
                  y*cellSize,
                  (x+1)*cellSize,
                  y*cellSize,
                  wallPaint)
              }
  
              if (cells[x][y].leftWall){
                  canvas.drawLine(
                      x*cellSize,
                      y*cellSize,
                      x*cellSize,
                      (y+1)*cellSize,
                      wallPaint)
              }
  
              if (cells[x][y].bottomWall){
                  canvas.drawLine(
                      x*cellSize,
                      (y+1)*cellSize,
                      (x+1)*cellSize,
                      (y+1)*cellSize,
                      wallPaint)
              }
  
              if (cells[x][y].rightWall){
                  canvas.drawLine(
                      (x+1)*cellSize,
                      y*cellSize,
                      (x+1)*cellSize,
                      (y+1)*cellSize,
                      wallPaint)
              }
          }
      }
  
  }
  
  }
  
  class Cell(var col:Int = 0, var row: Int = 0 ){
  var topWall = true
  var leftWall = true
  var bottomWall = true
  var rightWall = true
  var visited = false
  
  }
  </code></pre>