title: Error of java.lang.RuntimeException: Unable to instantiate activity ComponentInfo KOTLIN/AndroidStudio
body: <p>I am trying to do a copy of Space Invaders with Kotlin and Android Studio to learn more about this kind of development but I have this error happening :</p>
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: main
      Process: com.example.spaceinvaders, PID: 3982
      java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.spaceinvaders/com.example.spaceinvaders.GameView}: java.lang.InstantiationException: java.lang.Class&lt;com.example.spaceinvaders.GameView&gt; has no zero argument constructor
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2914)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3119)
          at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
          at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
          at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1839)
          at android.os.Handler.dispatchMessage(Handler.java:106)
          at android.os.Looper.loop(Looper.java:201)
          at android.app.ActivityThread.main(ActivityThread.java:6864)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
       Caused by: java.lang.InstantiationException: java.lang.Class&lt;com.example.spaceinvaders.GameView&gt; has no zero argument constructor
          at java.lang.Class.newInstance(Native Method)
          at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:69)
          at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:45)
          at android.app.Instrumentation.newActivity(Instrumentation.java:1216)
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2902)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3119) 
          at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
          at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
          at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1839) 
          at android.os.Handler.dispatchMessage(Handler.java:106) 
          at android.os.Looper.loop(Looper.java:201) 
          at android.app.ActivityThread.main(ActivityThread.java:6864) 
          at java.lang.reflect.Method.invoke(Native Method) 
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547) 
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873) 
  </code></pre>
  <p>I have two activities: one for the menu and one for the game. When I try to pass from one menu to the other by clicking on a button, it crashes.
  Here there are the other codes :</p>
  <p>HomeScreen :</p>
  <pre><code>class HomeScreen : Activity(), View.OnClickListener{
  
      lateinit var nbAliens : TextView
      lateinit var SPACE_SHIP : Bitmap          //L'image choisi par le joueur
      var ALIENS_NUMBER : Int = 0               //Le nombre d'ennemi choisi par le joueur
      var flagOK : Boolean = false
  
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_ecran_accueil)
          nbAliens = findViewById(R.id.textViewNbEnnemis)
          btnMinus.setOnClickListener(this)
          btnPlus.setOnClickListener(this)
          imgBtnSpaceShip1.setOnClickListener(this)
          imgBtnSpaceShip2.setOnClickListener(this)
          btnStart.setOnClickListener(this)
      }
  
      override fun onClick(v: View?) {
          when (v){
              btnMinus -&gt;{
                  //Modify the textView et change ALIEN_NUMBER 
                  var i = nbAliens.text.toString().toInt()
                  if (i &gt; 7) i--
                  nbAliens.text = i.toString()
                  ALIENS_NUMBER = i
              }
              btnPlus -&gt;{
                  var i = nbAliens.text.toString().toInt()
                  if (i &lt; 21) i++
                  nbAliens.text = i.toString()
                  ALIENS_NUMBER = i
              }
              imgBtnSpaceShip1 -&gt;{
                  /*When you click in the imageButton, you chose your SpaceShip Image
  The first one's background goes green while the other becomes all grey
  
  */
                  val color = Color.argb(130,255,255,255)
                  imgBtnSpaceShip1.setColorFilter(Color.TRANSPARENT)
                  imgBtnSpaceShip2.setBackgroundColor(color)
                  imgBtnSpaceShip2.setColorFilter(color)
                  imgBtnSpaceShip1.setBackgroundColor(Color.GREEN)
                  SPACE_SHIP = BitmapFactory.decodeResource(resources, R.drawable.space_ship1)
                  flagOK = true
              }
              imgBtnSpaceShip2 -&gt;{
                  val color = Color.argb(130,255,255,255)
                  imgBtnSpaceShip2.setColorFilter(Color.TRANSPARENT)
                  imgBtnSpaceShip1.setBackgroundColor(color)
                  imgBtnSpaceShip1.setColorFilter(color)
                  imgBtnSpaceShip2.setBackgroundColor(Color.GREEN)
                  SPACE_SHIP = BitmapFactory.decodeResource(resources, R.drawable.space_ship2)
                  flagOK = true
              }
              btnStart -&gt; {
                  //Change from HomeScreen to GameView
                  if (flagOK) {
                      val intent: Intent =
                          Intent(applicationContext, GameView::class.java)
                      startActivity(intent)
                      finish()
                  }else {
                      Toast.makeText(this, &quot;You have to pick a spaceship to start!&quot;, Toast.LENGTH_LONG).show()
                  }
              }
          }
      }
  
  
  }
  </code></pre>
  <p>GameView :</p>
  <pre><code>class GameView @JvmOverloads constructor (context: Context, var imgSpaceShip: Bitmap, attributes: AttributeSet? = null, defStyleAttr: Int = 0): View(context, attributes,defStyleAttr){
  
      private lateinit var imgAlienGreen : Bitmap
      private lateinit var imgAlienRed : Bitmap
      private lateinit var imgAlienWhite : Bitmap
      private var alien_margin by Delegates.notNull&lt;Float&gt;()
      private var alien_side by Delegates.notNull&lt;Float&gt;()
  
      val game : Game = Game()
      val backgroundPaint = Paint()
  
      //Load images and resize it
      override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
          super.onSizeChanged(w, h, oldw, oldh)
  
          alien_margin = width*0.025f
          alien_side = (width - (game.NB_ALIENS_COLUMNS+1)*alien_margin)/game.NB_ALIENS_COLUMNS
          //There is another class Game for the logic of the game
          try{
              imgAlienGreen = BitmapFactory.decodeResource(resources, R.drawable.alien_green)
              imgAlienGreen = Bitmap.createScaledBitmap(imgAlienGreen, alien_side.toInt(), alien_side.toInt(), true)
  
              imgAlienRed = BitmapFactory.decodeResource(resources, R.drawable.alien_red)
              imgAlienRed = Bitmap.createScaledBitmap(imgAlienRed, alien_side.toInt(), alien_side.toInt(), true)
  
              imgAlienWhite = BitmapFactory.decodeResource(resources, R.drawable.alien_white)
              imgAlienWhite = Bitmap.createScaledBitmap(imgAlienWhite, alien_side.toInt(), alien_side.toInt(), true)
  
              imgSpaceShip = Bitmap.createScaledBitmap(imgSpaceShip, alien_side.toInt(), alien_side.toInt(), true)
          }catch (exception : Exception) {
              Log.e(&quot;ERROR&quot;, &quot;Cannot load images&quot;);
          }
      }
  
      //Build the rectangles where the images will be set on.
      private fun alienRectF(index: Int) : RectF{
          val x : Float = alien_margin + alien_side
          val y : Float = height + 0.17f
          return RectF(x, y, x+alien_side, y+alien_side)
      }
     //It finishes here but I will continue coding after resolving it
  }
  </code></pre>
  <p>I have no idea of what is going on. Thanks for the help!</p>