Questions tagged [kotlin-lateinit]
78 questions
1
vote
1 answer
Converting a callback to a suspendCoroutine, when the callback is a field of class
I want to convert some 3rd-party API based on callbacks to simple suspend functions that are easy to use. Here's a simplified example of mine implementation.
class LibraryWrapper {
private lateinit var onFooFired: (Boolean) -> Unit
private…

Sergey Medgaus
- 33
- 3
1
vote
1 answer
Variable in base class is null when initialized from derived class but called from super
I'm having trouble converting an inherited singleton pattern from Java to Kotlin.
open class ThumbnailManager {
lateinit var data: Data
companion object{
fun getInstance(): ThumbnailManager{
return ThumbnailManager()
…

galaxigirl
- 2,390
- 2
- 20
- 29
1
vote
1 answer
Initializing on item selected listener (Custom Spinner Adapter)
I have created a custom spinner adapter which returns two views (item_new_area & item_area), item_new_area is static with an option Add New and item_area populated dynamic.
When Add new is selected,I want to launch the dialog for add new area but i…

braop
- 186
- 12
1
vote
2 answers
Kotlin Unit Test variable declaration lateinit vs lazy vs nullable vs non-nullable
We are converting most of our unit tests from Java to Kotlin. What's the best way to declare a variable in our unit tests (across but not all some might still have use cases to use lateinit, lazy, nullable etc...) and why.

Mike
- 1,313
- 12
- 21
1
vote
1 answer
lateinit property not initialized after pick file explorer
I have an activity that let user select file from explorer, retrieve the result in onActivityResult() and save the result inside an object called Property
I have a lateinit variable as follow :
lateinit var uploadProperties: Property
And the code to…

dito cesartista
- 209
- 1
- 10
1
vote
4 answers
Kotlin: are companion object lateinit vars initialised once?
Given the code below:
class Foo {
companion object {
lateinit var names: Array
}
init {
names = arrayOf("George", "Keith", "Martha", "Margret")
}
}
If I created two instances of Foo:
var foo1 = Foo();
var…

pnizzle
- 6,243
- 4
- 52
- 81
1
vote
2 answers
how to Initialize the lateinit variable?
I am trying to run the open source app in which i am getting the error as
lateinit property textInput has not been initialized
The main code where the textInput is used
class MainActivity : BaseActivity() {
private val drawerToggle by lazy {…

Yashwin.L
- 19
- 1
- 9
1
vote
2 answers
How to fix assignment are not expressions kotlin and only expression are allowed
in the below, i am trying to lateinit a variable as shown. however after folloing some examples in the internet i understood the concept of it but however i received the below posted error message due to
the code stated in the method…

Amrmsmb
- 1
- 27
- 104
- 226
1
vote
1 answer
RecyclerView lateinit property mClickListener has not been initialized
I've found a tutorial on how to implement onClickListener to RecyclerView but then I couldn't find out why the code doesn't work. The log says that the lateinit property has not been initialized. I am not sure why it said that. How would I be able…

CoderUni
- 5,474
- 7
- 26
- 58
0
votes
2 answers
LateInitializationError : Field 'titleControl' has not been initialized
I'm new to flutter and I have this error after running someone else project that I clone. The error is this LateInitializationError : Field 'titleControl' has not been initialized.
I don't know which code caused the Error. This is the code that I…

Josh Lee
- 81
- 5
0
votes
0 answers
lateinit var is not initialized
I am confused as to why this lateinit var koinApp is sometimes not initialized...
object MyKoin {
lateinit var koinApp: KoinApplication
}
class Builder {
init {
MyKoin.koinApp = koinApplication {
assertMainThread() //…

Thomas Cook
- 4,371
- 2
- 25
- 42
0
votes
1 answer
lateinit property myListener has not been initialized
this is the error
kotlin.UninitializedPropertyAccessException: lateinit property myListener has not been initialized
at com.example.fitnesscult.MyAdapter.onCreateViewHolder(MyAdapter.kt:30)
at…
0
votes
2 answers
Kotlin null pointer when checking for null state
I have a codeblock with a simple null check that causes an exception
kotlin.UninitializedPropertyAccessException: lateinit property currentJob has not been initialized
at…

user1743524
- 655
- 1
- 7
- 14
0
votes
1 answer
lateinit property mAdapter has not been initialized. How to solve this problem?
MainActivity.kt
class MainActivity : AppCompatActivity(), NewsItemclicked {
private lateinit var mAdapter: NewsListAdapter
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
…

Soudeep Ghosh
- 3
- 2
0
votes
2 answers
Where can I put the method isInitalized to check the lateinit variable?
I am making an app in Android Studio with Kotlin. With the lateinit variable in the ListFragment throws me an error called:
kotlin.uninitializedpropertyaccessexception: lateinit property dbhelper has not been initialized.
I know that there is a…

setNameDani
- 3
- 3