https://kotlinlang.org logo
Docs
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
stackoverflow
  • u

    user

    07/21/2022, 3:01 PM
    Descending order ZoneDateTime in list kotlin I have list of ZoneDateTime. I want to order by descending order. I didn't find the solution. Can some one guide me. NearestResult(day=2020-05-09T20:09:03+01:00, event=xyz) NearestResult(day=2020-05-09T09:15:15+01:00, event=abc) NearestResult(day=2020-05-09T23:15:15+01:00, event=qwe) NearestResult(day=2020-05-09T14:00:40+01:00, event=aks) NearestResult.kt data class NearestResult( val day: ZonedDateTime, val event: String ) I tried some code but it's not working lis.groupBy { it.day...
  • u

    user

    07/21/2022, 3:01 PM
    Spring Boot Kotlin: Handling Controller Binding Errors I am having trouble catching and handling binding errors in my Spring Boot Kotlin application. Not sure if it's a Kotlin issue (I haven't had this problem in Java before), a form-urlencoded issue (I usually use JSON) or a me issue. Here's my controller code: @PostMapping( path = ["/"], consumes = [MediaType.APPLICATION_FORM_URLENCODED_VALUE], produces = [MediaType.APPLICATION_FORM_URLENCODED_VALUE, MediaType.TEXT_PLAIN_VALUE, MediaType.APPLICATION_JSON_VALUE] )...
  • u

    user

    07/21/2022, 3:01 PM
    What is a view model and how can I use it to replace findViewById with View Binding and I am working on a basic bluetooth app in android studio and I am having trouble with view binding. So far I have this in my MainActivity.kt override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMainBinding.inflate(layoutInflater) setContentView(binding.root) ... Later in the onCreate I have this line val btnONOFF = findViewById(R.id.btnONOFF) as Button and I would like to replace the findViewById using viewbinding but...
  • u

    user

    07/21/2022, 3:21 PM
    How can I filter array of <Any> by its type -Kotlin? I have an array arrayOf("Apple",46,"287",574,"Peach","3","69",78,"Grape","423") and I need to sort it: firstly numbers suppose to go like "3",46,"69"... and then words by alphabet... So I am trying first to divide them on separate arrays by type and then some manipulation. Do you have advice of how to solve this problem?
  • u

    user

    07/21/2022, 3:21 PM
    How to make End Date 1 day after the Start Day on android datePicker i have a project that should bring end date after the start date on android datepicker. (user will chose any date on start date and when user click end date what ever user choose end date should be one day after start date) for this purpose i have a Kotlin code as in below; private fun showDatePickerDialog(type: Int) { calendar = Calendar.getInstance() year = calendar!!.get(Calendar.YEAR) month = calendar!!.get(Calendar.MONTH) dayOfMonth =...
  • u

    user

    07/21/2022, 3:41 PM
    Is there a way to make the first digit of int always start with 1 in Kotlin Let's say I have the following class constructor: class Car(val brand: Brand,val modelName: String, val version: Int){} If for example, I want the version number to always start with 1. Is there a way to manipulate it in the class body to achieve this ? Meaning: val firstdigit:Int = abs(version).ToString().Substring(0,1) And then parse it to Int. But how to replace the original first digit after that? I'm just learning Kotlin and I got a bit stuck with this
  • u

    user

    07/21/2022, 4:01 PM
    Which Coroutine scope to use in AppWidgetProvider class? I am currently creating a widget and I am configuring the widget with a configuration activity and initializing the widget on onUpdate() of AppWidgetProvider. After that a CoroutineWorker will update the widget from time to time. I have set the updatePeriodMillis to 0. So simply my code would be override fun onUpdate(context: Context?, appWidgetManager: AppWidgetManager?, appWidgetIds: IntArray?) { if(!widget_configured) { //configure widget & start the service. } } So...
  • u

    user

    07/21/2022, 4:01 PM
    Flow<List>.map {} vs differents queries in room database I am developing an inventory management app in Kotlin. I developed a CustomListUtil class to manage user preferences and found it very useful to filter the lists from a function of the same class, so that my Dao had really few queries and then filtered the lists with Flow. At least at first glance my code looked neat and understood very well. Previous Dao code: @Dao interface ItemDao { @Insert (onConflict = OnConflictStrategy.IGNORE) suspend fun insert(item: Item) @Update //(onConflict =...
  • u

    user

    07/21/2022, 4:21 PM
    How to repeat empty Mono with (roughly) constant delays between attempts? How to repeat empty Mono with (roughly) constant delays between attempts so that it subtracts time spent executing Mono from the delay? I tried this val delay = Duration.ofSeconds(5) var count = 0 val res = Mono.defer { Mono.fromCallable { count++ }.flatMap { c -> println("${Instant.now()}: $c") if (c < 3) { // Thread.sleep(2000) Mono.delay(Duration.ofMillis(1000)).then() // Mono.empty() } else...
  • u

    user

    07/21/2022, 5:01 PM
    Kotlin Client Generator support for Enum Unknown Values I'm wondering if there is a way to generate a kotlin lib from an openapi spec that will support a default value if it doesn't serialize a known enum value. Ex: the Java Generator has the enumUnknownDefaultCase flag in its spec Ref from the kotlin generator seems to read in the config for the moshi serializer <a...
  • u

    user

    07/21/2022, 5:21 PM
    How to bring an Android launcher from background to foreground from a long-running service? I am creating an Android launcher that should be brought to the foreground after an IntentService that started before, finishes doing its logic (which takes up to 10 minutes), however, I read that IntentServices are deprecated. SO my quesions are: Do launchers keep running in the background even after closing them? If so, do I really need a intentservice that runs in the background to do background tasks ? What's the proper way of doing long-running logic processing in the background and then...
  • u

    user

    07/21/2022, 6:21 PM
    Alternative way for kotlin static methods Im kinda new to Kotlin and I was wondering how I could make a static method. I have this code: class Test() { var giorgor: String = "jiorgor" fun foo() = println(giorgor) } I want to access foo from somewhere else like this fun main() { Test.foo() // WantedOutput: jiorgor }
  • u

    user

    07/21/2022, 6:21 PM
    Google Map is not rotated I have this map fragment with android:rotation="90" to rotate it 90 degrees. However, it's not rotated when I run the app, why? Now, it looks like this:

    example▾

    But, I want it to look exactly like this:

    example▾

  • u

    user

    07/21/2022, 6:41 PM
    Native code awared of Kotlin coroutines on Android Is there any way to write a JNI adaptor for the native C library which supports external eventloop so that it could be Kotlin coroutines friendly? I need it for the Android app.
  • u

    user

    07/21/2022, 6:41 PM
    How to take payment using customer UPI ID How to take payment using customer UPI ID. How to set payee and payer in the link. upi://pay?pa=xxxxx@upi&amp;pn=payee&amp;am=5.00&amp;tn=Test_Transaction How to set payee Id,If customer enter his VPA.
  • u

    user

    07/21/2022, 6:41 PM
    Android crash when trying to use dependency injection to show language list on Bottom Sheet Fragment I like to show a language list when I press the button. I use dependency injection on the bottom sheet fragment but it crashes when the button is pressed. Is there something I do wrong in the code? Thanks. I try to use the following sample to learn the concept of hilt and digger. https://www.geeksforgeeks.org/dagger-hilt-in-android-with-example/ <a...
  • u

    user

    07/21/2022, 6:41 PM
    Loading data from a pointer and writing it back in Swift I'm building a video streaming app using Agora SDK (for Flutter). I also use a native-layer Raw Video Data plugin as a dependency, which gives me access to raw YUV420 frame buffers before they're encoded. I can access them via a Swift & Kotlin interface. I need to write...
  • u

    user

    07/21/2022, 7:01 PM
    How to increase Kotlin coroutines when running a test? I've implemented an integration test. It run some stuff, including two suspend functions which are run inside a launch{}. Now for some reason, when I run more than four of my integration tests, I have six, the fifth job gets cancelled and the IT fails. This is an excerpt of the code I'm testing: io.launch { temporaryStorage.storeFiles(businessProcess) .publishEvent(businessProcess, expectedDocumentType) .tapLeft { orchestrationFailure -> orchestrationFailure.handleFailure() } }...
  • u

    user

    07/21/2022, 7:01 PM
    Kotlin noarg plugin not initializing default values Hello I have the following code(jdk) build.gradle.kts plugins { kotlin("jvm") version "1.7.10" id("org.jetbrains.kotlin.plugin.noarg") version "1.7.10" application } noArg { annotation("com.MyAnnotation") } Classes and annotation annotation class MyAnnotation @MyAnnotation class A( var a: String = java.util.UUID.randomUUID().toString() ) @MyAnnotation class Ab ( var a: String = java.util.UUID.randomUUID().toString(), var b: String ) When I initialize A and Ab...
  • u

    user

    07/21/2022, 7:21 PM
    I'm trying to implement a Intent in Android to send GIFs directly inside chats in Whatsapp without the preview activity Can anybody help me out in this problem,there is nothing I found in android documentation and whatsapp help center documentation they are only allowing the 512x512px to directly send, but I want to send Gifs which are even larger than this size
  • u

    user

    07/21/2022, 7:21 PM
    onNotify ble android never called what I'm doing wrong? I want to read records data from glucometer. That characteristic is not able to read or write, only set notifications. Iuse writeDescriptor and it's return true but there is no any onCharacteristicChanged callbacks override fun onServicesDiscovered(gatt: BluetoothGatt, status: Int) { if (status == BluetoothGatt.GATT_SUCCESS) { Log.w("BLE", "onServicesDiscovered ") val service = gatt.getService(GLUCOSE_SERVICE) val characteristic =...
  • u

    user

    07/21/2022, 7:21 PM
    Can't increase ThreadPoolExecutor's core pool size I'm having issues dynamically increasing the core pool size of a ThreadPoolExecutor in kotlin. First I define my ThreadPoolExecutor like this: val POOL = Executors.newFixedThreadPool(20) as ThreadPoolExecutor Then I add some tasks to the ThreadPoolExecutor. After some time, in a different thread, while the tasks are still running: POOL.corePoolSize += 20 It returns: Exception in thread "Thread-0" java.lang.IllegalArgumentException at...
  • u

    user

    07/21/2022, 8:21 PM
    Add the Instance of the class to constructor parameter property I have the following class structure. The CarModel Class has a defects List which is of Type CarDefects. And I wanted to add the instance of the CarDefects class into this list of defects of carModel which is passed as a parameter for the CarDefects constructor. However i cannot the use the add method and the error message says the following: Unresolved reference: add class CarModel(val brand: Brand, val modelName: String, val version: Int){ var defects: List? = null inner class...
  • u

    user

    07/21/2022, 8:21 PM
    Unit Test Firestore CallbackFlow I wrote the following code to test Firestore data reading with coroutines' runTest function: @Test fun `callbackFlow should read trip`() = runTest { log("test started") var result: DocumentSnapshot? = null val flow = callbackFlow { log("callbackFlow started") val listener = firestore .collection("/collection") .addSnapshotListener { snapshot, e -> e?.let {...
  • u

    user

    07/21/2022, 8:21 PM
    Kotlin instanceOf Iterable I want to verify that Any is Iterable override fun funnyFunction(context: Any): Any { if(context is Iterable) // do something } Warning that i get is One type argument expected. Use 'Iterable' if you don't want to pass type arguments In Java the code is Object funnyFunction(final context: Object) { if(context instanceof Iterable) // do something } Anyone have idea how to do it?
  • u

    user

    07/21/2022, 8:41 PM
    Android + Kotlin + Hilt: [Dagger/MissingBinding] xxx cannot be provided without an @Provides-annotated method Still digging into the basic concepts of Hilt, and trying to make a simple example to work into my app with no success. My app is a multi-module app, and apart from the application project (where all the activities are) I have some modules. "Common" is one of them which includes some helpers (for the moment static classes (which I'm trying to migrate to Hilt modules). For my example, I've picked up the "ExceptionHandler" class (supposedly converted to a Hilt module) and trying to inject it in...
  • u

    user

    07/21/2022, 8:41 PM
    mockK throwing exception on mocked class methods @BeforeEach init { MockKAnnotations.init(this) class1 = Class1(obj1,obj2) } @Test fun `test something`(){ every { obj1.someMethod(any()) } returns "dummyResult" val request = Request().also { it.clientId = "partner-client-id" } val response = Response().also{ it.accessToken="dummyAccessToken" } with (class1) { every { methodOfClass1(request) }...
  • u

    user

    07/21/2022, 9:01 PM
    AWS SDK Kotlin is installed but can not be found in project Im building a REST API and part of it shall be handling media upload and download to and from AWS S3. Since im using Kotlin with Maven, I added a dependency to AWS S3 SDK to my pom.xml file like this: aws.sdk.kotlin s3 0.16.0 Maven install went well and everything passes together with my tests etc. Problem occurs when im trying to add S3Client to my code, the whole SDK is not found. The library is found in dependency tab in my InteliJ IDEA, also as part of external libraries as...
  • u

    user

    07/21/2022, 9:01 PM
    How can use filter and contains with multi-ArrayList in Kotlin so I only have elements which match the condition? I have a class called Person data class Person( val id: Int, val name: String ) data class IDs( val id : Int, val active : Boolean ) and an array list that has numbers of ids and another list of Persons val myStu = listOf(Person(1, "Name_1"), Person(2, "Name_2"), Person(3, "Name_3")) var ids = listOf(IDs(1,false),IDs(2,true),IDs(3,true)) var newIds = listOf(2,3,4,6) First I want to apply two actions to the myStu, first is to have a list that include all the items from myStu...
  • u

    user

    07/21/2022, 9:21 PM
    I want to set a value in textField and not being able to change this value, only possible to insert new values. (kotlin) I have a registration form, when I select an especific option on input, a textField this form receive a value that cannot be changed, being able to only type with other values ​​in this textField.
Powered by Linen
Title
u

user

07/21/2022, 9:21 PM
I want to set a value in textField and not being able to change this value, only possible to insert new values. (kotlin) I have a registration form, when I select an especific option on input, a textField this form receive a value that cannot be changed, being able to only type with other values ​​in this textField.
View count: 8