Пытаюсь получить доступ к глобальной переменной из активити, но получаю ошибку:
lateinit property matchCardAdapter has not been initialized.
Как её исправить?
fun initMatchCardList():MatchCardAdapter{
Log.e("Init","match car init")
return MatchCardAdapter(mutableListOf())
}
class GlobalVariables:Application() {
lateinit var matchCardAdapter:MatchCardAdapter
override fun onCreate(){
super.onCreate()
matchCardAdapter = initMatchCardList()
}
}
class ListOfMatches : AppCompatActivity() {
private lateinit var btnNewMatch: View;
private lateinit var rvMatches:RecyclerView
private lateinit var matchCardAdapter: MatchCardAdapter
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_list_of_matches)
btnNewMatch = findViewById(R.id.btnNewMatch)
rvMatches = findViewById(R.id.rvMatches)
ProgressButton(this,btnNewMatch,"Создать матч")
// ОШИБКА ЗДЕСЬ
matchCardAdapter = GlobalVariables().matchCardAdapter
rvMatches.adapter = matchCardAdapter
rvMatches.layoutManager = LinearLayoutManager(this)
btnNewMatch.setOnClickListener(View.OnClickListener { v->
val match = MatchCard(null, Calendar.getInstance().getTime(),false,Math.random().toString(),"s player",ArrayList<Int>(),ArrayList<Int>(),"15","40")
matchCardAdapter.addMatch(match)
})
}
override fun onBackPressed() {
// Do Here what ever you want do on back press;
}
}