Questions tagged [kotlin]

Kotlin is a cross-platform, statically typed, general-purpose high-level programming language with type inference. This tag is often used alongside additional tags for the different targets (JVM, JavaScript, native, etc.) and libraries/frameworks (Android, Spring, etc.) used by Kotlin developers, if the question relates specifically to those topics.

Kotlin is an open-source, statically typed programming language supported and developed by JetBrains. It supports JVM bytecode, JavaScript, and Native code as compilation targets, and it has been an officially supported first-class language on Android since Google I/O 2017. The goals with Kotlin are to make it concise, safe, versatile, and have it be seamlessly interoperable with existing Java libraries.

On June 9th 2022, The Kotlin team released version 1.7.0 (announcement / github release tag).

The current major version is 1.7.

How to ask

If you are using Kotlin and your question is related to it, then you should add this tag. You should explain what do you intend to achieve, how did you try to achieve it, what the experienced behavior is and how is that different from your expectations.

Kotlin Reference Documentation

Kotlin Books

Development tools

Useful links

91039 questions
22
votes
7 answers

Unsupported metadata version. Check that your Kotlin version is >= 1.0: java.lang.IllegalStateException

I changed my Kotlin version from 1.6.10 to 1.7.0. from this implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.10' upgrated to implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.0' But Hilt throws an error. My Hilt version is…
Hasan Kucuk
  • 2,433
  • 6
  • 19
  • 41
22
votes
1 answer

Why @DelicateCoroutinesApi is required for the use of GlobalScope

I am using Kotlin and right now android studio suggest me to add This is a delicate API and its use requires care. Make sure you fully read and understand documentation of the declaration that is marked as a delicate API. and when I click to add…
Adarsh Dhakad
  • 347
  • 1
  • 3
  • 10
22
votes
3 answers

How to disable and enable scrolling in LazyColumn/LazyRow in Jetpack Compose?

I want to dynamically enable and disable scrolling programmatically in a LazyColumn. There don't seem to be any relevant functions on LazyListState or relevant parameters on LazyColumn itself. How can I achieve this in Compose?
d-feverx
  • 1,424
  • 3
  • 16
  • 31
22
votes
4 answers

How to enable spring security kotlin DSL?

How can we enable support for the spring security kotlin DSL? As you can see from the Screenshot of the IDE (IntelliJ), the DSL is not available: This is the full SecurityConfig.kt file: package com.example.backend.core import…
Stuck
  • 11,225
  • 11
  • 59
  • 104
22
votes
1 answer

How to mock the view model with Hilt for unit testing fragments?

I've got an android app setup for dependency injection using Hilt, and would like to unit test my fragments. I'm currently creating my view model using: private val viewModel: ExampleViewModel by viewModels() And I am creating the fragment for…
kmell
  • 223
  • 2
  • 4
22
votes
2 answers

What is the appropriate way of calling suspending functions inside a suspendCoroutine block?

I need to call a suspending function inside a suspendCoroutine block, before I call continuation.resume(). What is the appropriate way of doing that? private suspend fun someFunction() = suspendCoroutine { cont -> //... val myResult =…
bernardo.g
  • 826
  • 1
  • 12
  • 27
22
votes
2 answers

Unable to Execute code after Kotlin Flow collect

I'm trying to execute some code after calling collect on a Flow. I'm still kind of new to using Flows so I don't understand why the code after the function doesn't get called. How I use the Flow: incidentListener =…
kobowo
  • 2,529
  • 2
  • 24
  • 37
22
votes
2 answers

Kapt annotation processing - how to show full stacktrace

I am working on a android project using Kotlin, Databinding and Room. Sometimes the build fails with a error message, containing no information about what exactly went wrong, except that it has something to do with the annotation processor (which…
tarbos
  • 241
  • 1
  • 2
  • 6
22
votes
1 answer

java.lang.UnsupportedOperationException: Reflective setAccessible(true) disabled

When I run my Ktor application with gradle run then I've got the following exception: 19:21:11.795 [main] DEBUG io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework 19:21:11.810 [main] DEBUG…
softshipper
  • 32,463
  • 51
  • 192
  • 400
22
votes
2 answers

Android and Kotlin coroutines: inappropriate blocking method call

I have the following class: class Repository( private val assetManager: AssetManager, private val ioDispatcher: CoroutineDispatcher = Dispatchers.IO ) { suspend fun fetchHeritagesList(): HeritageResponse = withContext(ioDispatcher) { …
noloman
  • 11,411
  • 20
  • 82
  • 129
22
votes
2 answers

What is the purpose of inner class in kotlin?

I am new to kotlin. i am going through Nested class and inner class concepts in kotlin. Below is a example of nested class. fun main(args: Array) { val demo = Outer.Nested().foo() // calling nested class method print(demo) } class…
Gaju Kollur
  • 2,046
  • 5
  • 23
  • 47
22
votes
1 answer

How to mock android context using mockk library

I am new in JUnit testing on Android and I'm testing a function, which is using android context object to get a string resources and making some comparsions. How can I mock android context object to successfully test this function? For testing I'm…
Taras Stavnychyi
  • 895
  • 1
  • 9
  • 14
22
votes
6 answers

How to format in Kotlin date in string or timestamp to my preferred format?

I'm getting date data from weather API in two versions. The first one is just string like this: 2019-08-07 09:00:00 and like this: 1565209665. How do I change it to just the name of the day or day and month? For example Monday, August. I tried…
beginner992
  • 659
  • 1
  • 9
  • 28
22
votes
7 answers

Remove ViewPager2 Overscroll animation

Can't find a way to remove the ViewPager2 overscroll shadow animation. I know on ViewPager, you can directly just set the overscrollMode attribute to never, however, it does not work on ViewPager2 Already tried the…
Daniel Kim
  • 899
  • 7
  • 11
22
votes
2 answers

Kotlin - Will mutableMapOf() preserve the order which i have entered

I need to know will the map in kotlin preserve the order of the entries which i have entered during insertion Example val data = mutableMapOf() data.put("some_string_1","data_1") . . . data.put("some_string_n","data_n") will the…
Stack
  • 1,164
  • 1
  • 13
  • 26