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
21
votes
2 answers

Could not resolve com.google.guava:guava:30.1-jre - Gradle project sync failed. Basic functionality will not work properly - in kotlin project

It was a project that used to work well in the past, but after updating, the following errors appear. plugins { id 'com.android.application' id 'kotlin-android' } android { compileSdkVersion 30 buildToolsVersion "30.0.3" …
happynewmind
  • 363
  • 1
  • 2
  • 10
21
votes
3 answers

Difference between remember and rememberUpdatedState in Jetpack Compose?

I'm confused, can someone explain me the difference between: val variable by remember { mutableStateOf() } and val variable by rememberUpdatedState() When I check the source code of rememberUpdatedStates I actually see: remember { mutableStateOf()…
Stefan
  • 2,829
  • 5
  • 20
  • 44
21
votes
1 answer

How are Android activities handled with Jetpack Compose and Compose Navigation?

I'm currently studying Jetpack Compose in an attempt to build a feature-rich application using modern Android architecture components. Traditionally, each screen (or navigation unit) in my application would be either an activity or a fragment, each…
MrMikimn
  • 721
  • 1
  • 5
  • 19
21
votes
3 answers

How to control DropDownMenu position in Jetpack Compose

I have a row with a text align at the start and a image align at the end. When I press the image I'm showing a DropdownMenu, but this appear in the start of the row and I want that appear at the end of the row. I'm trying to use Alignment.centerEnd…
S.P.
  • 2,274
  • 4
  • 26
  • 57
21
votes
3 answers

Trying to use Room in an Android library but method ksp() (Kotlin Symbol Processing) is not found

I am following the android developers tutorial to implement a local room database. I am currently working on the Setup therefore changing my dependencies. But once I sync the app build.gradle it throws an error. A problem occurred evaluating project…
Magnus Offermanns
  • 410
  • 1
  • 3
  • 12
21
votes
6 answers

Text Composable dimensionResource not working as fontSize parameter

When I plug in fontSize = dimensionResource(id = R.dimen.textLabelTextSize) where the dimens or 54sp or 60sp depending on the device, I get an error on Text() "None of the following functions can be called with the arguments supplied." But when I…
galaxigirl
  • 2,390
  • 2
  • 20
  • 29
21
votes
6 answers

Cannot set non-nullable LiveData value to null

The error from the title is returned for the following code, which makes no sense private val _error = MutableLiveData() val error: LiveData get() = _error _error.postValue(null) //Error Cannot set non-nullable LiveData value to…
pedja
  • 3,285
  • 5
  • 36
  • 48
21
votes
10 answers

IntelliJ Kotlin - How do I fix "Ensure that you have a dependency on the Kotlin standard library" in a project?

I've been trying to set up a new Kotlin project in IntelliJ IDEA, using the default IntelliJ Build System (not Gradle) and JDK 15. Whenever it creates the default main.kt file, and I try to build and run the main function, which looks like this: fun…
A. P. Roblem
  • 455
  • 1
  • 3
  • 10
21
votes
5 answers

Kotlin Flow returned from Room does not update when an insert is performed from another Fragment/ViewModel

I have a Room database that returns a Flow of objects. When I insert a new item into the database, the Flow's collect function only triggers if the insert was performed from the same Fragment/ViewModel. I have recorded a quick video showcasing the…
Marc
  • 310
  • 1
  • 3
  • 6
21
votes
3 answers

How to end / close a MutableSharedFlow?

SharedFlow has just been introduced in coroutines 1.4.0-M1, and it is meant to replace all BroadcastChannel implementations (as stated in the design issue decription). I have a use case where I use a BroadcastChannel to represent incoming web socket…
Joffrey
  • 32,348
  • 6
  • 68
  • 100
21
votes
2 answers

Android unit testing view model that receives flow

I have a ViewModel that talks to a use case and gets a flow back i.e Flow. I want to unit test my ViewModel. I am new to using the flow. Need help pls. Here is the viewModel below - class MyViewModel(private val handle: SavedStateHandle,…
Ma2340
  • 647
  • 2
  • 17
  • 34
21
votes
6 answers

how to use Coroutine in kotlin to call a function every second

i just created an app where my function getdata() call every second to fetch new data from server and updateui() function will update view in UI i don't use any asynctask or coroutine in my app i wants to do this please tell me how i can do…
user12575366
  • 303
  • 1
  • 2
  • 8
21
votes
7 answers

NavController no current navigation node after device rotation

I am making app, which supports different device orientations. Navigation is carried out by Android Jetpack's Navigation. App main screen for landscape orientation is present below. It is list wrapper fragment (it is NavHostFragment, it is added to…
QuarK
  • 1,162
  • 2
  • 12
  • 27
21
votes
2 answers

Kotlin Coroutine Testing with Dispatchers.IO

So maybe there has been a tutorial going over this, but none of the ones I have read have addressed this issue for me. I have the structure as below and am trying to unit test, but when I go to test I always fails stating the repo method…
Adrian Le Roy Devezin
  • 672
  • 1
  • 13
  • 41
21
votes
1 answer

IntelliJ IDEA: How to specify main class in Kotlin?

I try to build a jar with Intellij Idea with Kotlin Gradle project. Idea doesn't see my main class when I try to configure Artifact here's my Gradle : plugins { id 'java' id 'org.jetbrains.kotlin.jvm' version '1.3.60' id…
Vlad Alexeev
  • 2,072
  • 6
  • 29
  • 59
1 2 3
99
100