### What I want to do

I'm trying to connect one spinner to another spinner on Kotlin with using the code on the former stack overflow question [how to make spinner depends on another spinner](https://stackoverflow.com/questions/29474829/how-to-make-spinner-depends-on-another-spinner).

### Problem

The original code from the former program was written in Java and Android Studio converted it to Kotlin automatically.

However, errors appeared on `MainActivity.kt` line 17 and 18.

What should I fix to emulate the program?

MainActivity.kt

```
    internal var spinner1: Spinner
    internal var spinner2: Spinner

```

Error Message

```
Property must be initialized or be abstract -

```

### Current code

MainActivity.kt

```
package com.example.twospinners

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.AdapterView
import android.R
import android.widget.ArrayAdapter
import android.widget.Toast
import androidx.test.core.app.ApplicationProvider.getApplicationContext
import android.widget.Spinner
import android.widget.AdapterView.OnItemSelectedListener
import android.app.Activity

class MainActivity : Activity(), OnItemSelectedListener {

    internal var spinner1: Spinner
    internal var spinner2: Spinner

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        spinner1 = findViewById(R.id.spinner1) as Spinner
        spinner2 = findViewById(R.id.spinner2) as Spinner
        val adapter1 = ArrayAdapter.createFromResource(
            this,
            R.array.array1, android.R.layout.simple_spinner_item
        )
        spinner1.adapter = adapter1
        spinner1.onItemSelectedListener = this
    }

    fun onCreateOptionsMenu(menu: Menu): Boolean {
        // Inflate the menu; this adds items to the action bar if it is present.
        menuInflater.inflate(R.menu.main, menu)
        return true
    }

    fun onOptionsItemSelected(item: MenuItem): Boolean {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        val id = item.getItemId()
        return if (id == R.id.action_settings) {
            true
        } else super.onOptionsItemSelected(item)
    }

    fun onItemSelected(
        parent: AdapterView<*>, view: View, position: Int,
        id: Long
    ) {
        if (spinner1.selectedItem == "mobile") {
            Toast.makeText(
                applicationContext, "Mobil dipilih",
                Toast.LENGTH_SHORT
            ).show()

            val adapter2 = ArrayAdapter.createFromResource(
                this,
                R.array.mobile_array, android.R.layout.simple_spinner_item
            )
            spinner2.adapter = adapter2
        } else {
            val adapter2 = ArrayAdapter.createFromResource(
                this,
                R.array.motor_array, android.R.layout.simple_spinner_item
            )
            spinner2.adapter = adapter2
        }

    }

    override fun onNothingSelected(parent: AdapterView<*>) {
        // TODO Auto-generated method stub
    }

}

```

activity\_main.xml

```xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.stackspinner.MainActivity" >

    <Spinner
        android:id="@+id/spinner1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <Spinner
        android:id="@+id/spinner2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/spinner1" />

</RelativeLayout>

```

strings.xml

```xml
<resources>

    <string name="app_name">Application Name</string>
    <string name="hello_world">Hello world!</string>
    <string name="action_settings">Settings</string>

    <string-array name="array1">
        <item>mobile</item>
        <item>motor</item>
    </string-array>
    <string-array name="mobile_array">
        <item>Android</item>
        <item>blackberry</item>
        <item>apple</item>
    </string-array>
    <string-array name="motor_array">
        <item>Audi</item>
        <item>BMW</item>
        <item>unicorn</item>
    </string-array>
</resources>

```

### Developing Environment

Android Studio 3.5.3

Emulator Pixel2 API 28

OS 4.4 KitKat