Questions tagged [kotlin-lateinit]
78 questions
0
votes
2 answers
lateinit variable not being initialized in a thread
So I'm working with the google sheets api in an android app and I'm trying to get the credentials in a separate thread. This is what I have:
GoogleSheets is a class I created to get credentials and cell values of my spreadsheet
private lateinit var…
user17792511
0
votes
1 answer
Difficulty in @Value Injection in @PropertySource in Kotlin/SpringBoot
I am new to Kotlin. So I was trying to write a @PropertySource class with @Value injection in Spring Boot, so that it can be used elsewhere.
I have written the class like this:
import org.springframework.beans.factory.annotation.Value
import…

hell_storm2004
- 1,401
- 2
- 33
- 66
0
votes
1 answer
Android - kotlin.UninitializedPropertyAccessException: lateinit property homeActivityBinding has not been initialized
I have a BaseFragment class that is extended by all fragments in my app. And i have a HomeActivity class is a starting activity and also has some generic functionality in it.
Here is my HomeActivity code:
class HomeActivity :…

srisindhu saride
- 391
- 6
- 25
0
votes
0 answers
Using lateinit in Kotlin
fun main() {
val lateData = LateData()
with(lateData) {
lateinitNumber = 10
nullableNumber.printLog()
lateinitNumber.printLog()
}
}
class LateData {
var nullableNumber: Int? = null
lateinit var…

JunJaBoy
- 25
- 4
0
votes
5 answers
How to deal with non initialized lateinit vars
I'm migrating a project from java to kotlin, and that project used a lot of variables that can be null and they are not initialized until some interaction with the user or external jobs have been done.
I'm trying to use kotlin null safety…

NullPointerException
- 36,107
- 79
- 222
- 382
0
votes
1 answer
spring boot startup process failed with lateinit var not initialized : DI Issue
I'm buidling a backend that will fetch some data from several externals APIs, to populate DB after some processes, and then expose these data via a rest api. Using JPA and postgresql, in springboot.
I have created the entities, repositories and…

Jerome
- 2,429
- 2
- 22
- 37
0
votes
2 answers
How to initialize variable for FindBy annotation in Selenium with Kotlin?
What is the best way to initialize a variable with the Selenium's FindBy annotation in Kotlin?
Something like
@FindBy(id = "example")
private lateinit var button: WebElement
or
@FindBy(id = "example")
private val button: WebElement? =…

ᴜsᴇʀ
- 1,109
- 2
- 9
- 23
0
votes
2 answers
How can I access to data class object from activity?
I am trying to access to data class (Content)and I would like to use object(val isSelected: Boolean?)from PictureActivity. However, it causes UninitializedPropertyAccessException: lateinit property content has not been initialized. Do you know how…

John
- 17
- 1
- 8
0
votes
5 answers
How do I ensure lateinit variable initialization before it is needed?
I have an app that launches the majority of the time, but every 7 or so launches it crashes with the error:
kotlin.UninitializedPropertyAccessException: lateinit property weekdayList has not been initialized
This is a clear error, I'm just not…

schnondle
- 121
- 14
0
votes
0 answers
How to force initialization on App Context?
in order to use application context anywhere, I use this code:
class App : Application() {
companion object {
lateinit var instance: App private set
fun isInstanceInitialized() = ::instance.isInitialized
}
override fun…

jonadv
- 434
- 6
- 16
0
votes
2 answers
"kotlin.UninitializedPropertyAccessException: lateinit property madapter has not been initialized at..." when setting up RecyclerView Adapter
Line throwing error:
recyclerView.adapter = mAdapter
Code:
class MainActivity : AppCompatActivity(), NewsItemClicked {
private lateinit var recyclerView:RecyclerView
private lateinit var mAdapter: NewsListAdapter
override fun…

Adrishyantee Maiti
- 23
- 1
- 4
0
votes
3 answers
How to execute code in init block after property y is initialized
I would like to call some code inside my class init block, after a property y is initialized. I've tried it with this::y.isInitialized ..., but the problem here is that at the creation of the class, the property is not initialized (which it gets…

Andrew
- 4,264
- 1
- 21
- 65
0
votes
1 answer
How to check outside the companion object if a lateinit var inside it is initialized
How do I check if user variable is initialized when an instance of MyClass is created?
class MyClass
{
companion object
{
lateinit var user:User
}
init
{
//initialize if not initialized
…

Tayyab Mazhar
- 1,560
- 10
- 26
0
votes
2 answers
lateinit property not assigned value soon enough?
My code works 9,999 out of 10,000 times. But, for about once in every 10,000 times, the application crashes to a UninitializedPropertyAccessException This is problematic as there are about 20,000~30,000 Android devices with my code in production.
It…

El Sushiboi
- 428
- 7
- 19
0
votes
1 answer
kotlin.UninitializedPropertyAccessException: lateinit property ans has not been initialized
The toPascalCase function is intended to convert strings containing spaces or - to Pascal case.
Below is my code ->
fun toPascalCase(str: String): String {
lateinit var ans: String
for(i in str) {
if(i != ' ' && i != '-') {
…

Yuseff
- 169
- 4
- 14