Questions tagged [kotlin-lateinit]

78 questions
2
votes
1 answer

app crashes as the late init property has not been initialized in android studio

I have a button, when i click on that, it should show the Alert dialog box, But app crashes when i click on that button I know the code flow is this but I dont know Where i had done my mistake private lateinit var btn: Button override…
2
votes
2 answers

When should we choose lateinit for an object ? Is it bad practice to make the binding as non-optional and lateinit?

I was declared a binding object in a fragment as lateinit var binding: EditInsuranceDialogBinding but a colleague said "This is a bad practice and Binding object should be Optional . " So in the declaration will be instead like this: var binding:…
Imene Noomene
  • 3,035
  • 5
  • 18
  • 34
2
votes
0 answers

How mock companion lateinit var?

I try to unit-test my presenter. I have method that update mark and when it failed, app shows toast with translated message. override fun updateMark(cameraId: Int, markId: Int, createData: MarkCreateData, context: Context) { view?.let { …
Hanna
  • 73
  • 6
2
votes
1 answer

Why am i getting kotlin.UninitializedPropertyAccessException even if lateinit property is initialized (probably)

Ok so I declared a lateinit var job in a widget as below. class TempHumidDisplayWidget : AppWidgetProvider(), CoroutineScope { private lateinit var job: Job override val coroutineContext: CoroutineContext get() = Dispatchers.Main +…
Animesh Sahu
  • 7,445
  • 2
  • 21
  • 49
2
votes
2 answers

Is this correct "lateinit var text : String?"?

I need to know if this line code is right, my teacher told me it's correct, but I disagree 'cause "lateinit" can't be with a variable that could be null or not. Line code: lateinit var text : String? Code: val cadena = null lateinit var…
2
votes
1 answer

Kotlin How to init BluetoothDevice

I want to use bluetooth printer in my project, but I got this error lateinit property mmDevice has been not initialized This is my code lateinit var device:String lateinit var mBluetoothAdapter: BluetoothAdapter lateinit var mmSocket:…
Firman
  • 21
  • 3
2
votes
0 answers

Access lateinit variable in Companion class

I have the following code: abstract class Database : RoomDatabase() { companion object { @Volatile lateinit var INSTANCE: Database private set fun init(context: Context) { val initialized =…
Maxim
  • 1,194
  • 11
  • 24
1
vote
1 answer

Mock trying to initialize fields

I have a class that I am trying to mock and call a method on it - @Component open class CloudStorageService { @Autowired lateinit var s3Client: AmazonS3 fun getSizeOfFirstMatchedObject(bucketName: String, directory: String, prefix: String):…
leoOrion
  • 1,833
  • 2
  • 26
  • 52
1
vote
2 answers

lateinit property for String has not been initialized

I just started to learn Hilt for dependency injection,and was on field injection and i am getting this following error even though i have initialised, lateinit property someRandomString has not been initialized Code for Appmodule…
1
vote
2 answers

Kotlin Late init variable access in more than two function of class

I want to access the late init variable in more than two functions how can i use it? Actually I want to remove the item from recyclerview when request accept or declined 1. Here is my fragment class lateinit var adapterPendingRequest:…
1
vote
1 answer

Lateinit property viewBinding has not been initialized

I'm using viewBinding successfully and never encountered this problem before. The property is initialized in onViewCreated like so: private lateinit var viewBinding: FragmentMainBinding override fun onViewCreated(view: View, savedInstanceState:…
Dan Abnormal
  • 1,188
  • 11
  • 21
1
vote
2 answers

"lateinit var overrides lateinit var"

Let's say I have a setup like so: abstract class FooTest { open lateinit var softAssertions: SoftAssertions ... reusable auxiliary functions ... } @ExtendWith(SoftAssertionsExtension::class) class BarTest: FooTest(){ …
User1291
  • 7,664
  • 8
  • 51
  • 108
1
vote
1 answer

check whether all lateinit members of a class have been initialized

I would like to create an extension method that helps me validate that all lateinit properties of a class have been initialized at a given point in time. I have come up with the following so far: fun Any.assertLateInitPropertiesAreInitialized() { …
Campi
  • 1,932
  • 1
  • 16
  • 21
1
vote
1 answer

lateinit property instance has not been initialized, while making an app

I'm a new developer(If I can call myself one) making an alarm app. I think I made other parts of the app but however hard I try, I can't find out how to fix the error. To access instance in AlarmManager.kt, I can't help but make instance companion…
jjin
  • 13
  • 1
  • 3
1
vote
2 answers

I have a code where a lateinit variable was initialized after it was called and I don't know how

While I was following up with the Developing Android Apps with Kotlin course on udacity I found that the instructor has made a lateinit variable lateinit var diceImage: ImageView as she will initialize it later before it's called *The lateinit…