https://kotlinlang.org logo
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/24/2022, 4:41 PM
    _uiState.value = uiState.value.copy() don't cause recompose There is some unresolved situation that happens with my code, my target is to change the property of an item in the "devices" list (update a boolean), The change should cause recompose of the view, but that doesn't happen, In addition, I can see that the item indeed changes with the debugger, but it also causes to add an additional item(an old copy without the included change) to show up in my list. Is there any idea how I was wrong with the new value assignment? The ViewModel private val...
  • u

    user

    07/24/2022, 4:41 PM
    Kotlin: user input into list I'm trying to create an app in Android Studio, where the user needs to input multiple names that are going to be stored in a list. I also wish to show the list to the users with ListView. Right now my approach is to have an EditText container where the user can input text, and then with the press of a button it would add it to the list "AllPlayersHidden". From there it would update the adapter, and then the ListView. Here's the main functional snippet: // List of players that is...
  • u

    user

    07/24/2022, 5:01 PM
    Autocomplete textview in fragments I want to create an autoCompleteTextView in a fragment but the Array adapter is bringing an error saying that 'none of the following function can be called with the arguments supplied'. So how should I use the array adapter in a fragment class? override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) val frequencyArray = ArrayList() frequencyArray.add("Daily") frequencyArray.add("Weekly") frequencyArray.add("Monthly")...
  • u

    user

    07/24/2022, 5:21 PM
    Can't connect kotlin to mySql even after adding the jdbc driver Im trying to connect kotlin to mySql but i've followed alot of tutorials and codes and then i receive that error and this is my code : No suitable driver found for jdbc:mysql://localhost:3306/mysql import java.sql.DriverManager import java.sql.Connection import java.sql.SQLException fun main() { Test.connection() } object Test { @JvmStatic var con: Connection? = null val url = "jdbc:mysql://localhost:3306/mysql" val username = "admin" val password = "123456" fun...
  • u

    user

    07/24/2022, 7:01 PM
    Testing custom exceptions in Kotlin with JUnit I have the following class data class CarDefects( private val _carModel: CarModel, private val _affectedYearsOfIssue: List, private val _defectCode: String ) { init { validateDefectCode(_defectCode) } } Validating function fun validateDefectCode(defectCode: String) { val pattern = Pattern.compile("^[a-zA-Z0-9-]*\$") val m = pattern.matcher(defectCode) if (defectCode.length !in 4..4) { throw InvalidDefectCodeException(defectCode, "Defect code...
  • u

    user

    07/24/2022, 7:01 PM
    Using MediatorLiveData to return if two LiveDatas are true Say I have two LiveData events, eventPlayerChose and eventOppChose, and I want to use MediatorLiveData eventRoundFinish to signal that both LiveDatas are true. Is this the best way to do so or is there a cleaner solution? private val _eventPlayerChose = MutableLiveData() val eventPlayerChose: LiveData get() = _eventPlayerChose private val _eventOppChose = MutableLiveData() val eventOppChose: LiveData get() = _eventOppChose // a round finishes when both players choose private val...
  • u

    user

    07/24/2022, 7:01 PM
    Kotlin flow map - make emit even if the value is same I want to know the kotlin flow flatMap working with jetpack compose I am having a flow for search and i am calling the api each time the search value changes. var search = MutableStateFlow("") And to call api var allItems = search.flatMapLatest{query-> flow{ emit(repository.getAllItems(query) } } It works perfectly fine , but excpet in one scenario. When the value of search is already "" an empty string, and i try to refresh the page , the code inside flatmap is not working...
  • u

    user

    07/24/2022, 7:41 PM
    How to access a function ,written in a fragment, in an activity I have created a function in a fragment that gets data from the fragment's UI. I would want to access it in my main Activity so as to store the data in cloud firestore This is the function in the fragment override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) fun getData(){ var dairyMealStock: Int = view?.findViewById(R.id.et_dairy_meal_stock)?.text.toString().toInt() var dairyMealDuration: Int =...
  • u

    user

    07/24/2022, 7:41 PM
    Why is the no lateinit block in Kotlin? The following code is valid Kotlin code: abstract class A { protected lateinit var v: X abstract fun f(): X class SubA : A() { override fun f(): X { return SubX() } init { v = f() } } } It defines an abstract class which has a lateinit var field and an abstract method that sets the value of that field. The reason behind this is that that method may be called later again, and its behavior should be defined in the...
  • u

    user

    07/24/2022, 8:21 PM
    Type mismatch: inferred type is String but Int was expected , Kotlin

    https://i.stack.imgur.com/0wAmw.png▾

    Task :app:compileDebugKotlin FAILED Type mismatch: inferred type is String but Int was expected
  • u

    user

    07/24/2022, 10:01 PM
    How to parse the different type of json When I call an api with specific parameter, I get a json like this: { “name”:“my name”, “family”:”my family” }, { “name”:“my name1”, “family”:”my family1” } But when I call same api with different parameter I get same JSON but with the different type for example an empty array : [] How can create a data model for this type of response in kotlin?
  • u

    user

    07/24/2022, 10:41 PM
    Android + Kotlin + Hilt: Cannot @Inject in a non activity class I recently started learning Hilt, and for now it's giving me more headaches than happiness, but I like challenges, so let's go to the point. I'm having plenty of problems understanding how to inject in non activity classes, for example to inject a Context or any other class. Most of my non activity classes were objects (singleton) so far, but as I wasn't able to inject into an object I decided to convert them to classes. I'm trying to inject with field injection, because if I use constructor...
  • u

    user

    07/25/2022, 12:21 AM
    Kotlin - Why can't I pass this method directly into the constructor, why do I need to use a lambda? I just started to learn Kotlin yesterday, so brace yourself for a potentially stupid question. class MyCustomViewAdapter(private val callback: (position: Int) -> Unit) : RecyclerView.Adapter() { ... } When I try to initialize this class, I need to pass in a callback parameter to receive events. MyCustomViewAdapter({ position -> onClickFlowerCallback(position)}) // this works MyCustomViewAdapter(onClickFlowerCallback) // this doesn't work? private fun onClickFlowerCallback(position:...
  • u

    user

    07/25/2022, 12:41 AM
    Why doesn't isAppearanceLightStatusBars affect on Status bar content color programmatically? I've tried to change the color of status bar content using isAppearanceLightStatusBars: override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_splash_screen) WindowCompat.setDecorFitsSystemWindows(window, false) val controller = ViewCompat.getWindowInsetsController(window.decorView) controller?.isAppearanceLightStatusBars = true } it doesn't change anything, but when i change it in...
  • u

    user

    07/25/2022, 1:21 AM
    What is the relationship between non-blocking I/O and Kotlin coroutines? What is the relationship between Kotlin coroutines and non-blocking I/O? Does one imply the other? What happens if I use blocking I/O? How does this affect performance?
  • u

    user

    07/25/2022, 1:41 AM
    Java vs Kotlin from IOS pov I’m an IOS developer, i decided to learn android development but there are two major languages, Java and Kotlin. From IOS development pov , is java to kotlin like objective-c to swift or is it something different. Moreover, apple developer provides all documentation for frameworks for IOS development, is there an official website like that for android development
  • u

    user

    07/25/2022, 1:41 AM
    Unable to multiply due compile error in kotlin Beginner question - Any idea why my code won't compile? I based it on a code given in this codelab and the given code compiles just fine. Any help is greatly appreciated :) <a href="https://developer.android.com/codelabs/basic-android-kotlin-training-tip-calculator?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-kotlin-unit-2-pathway-1%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-training-tip-calculator#3" rel="nofollow...
  • u

    user

    07/25/2022, 5:21 AM
    I want to give an exception to the first character in inputType of editText with Kotlin I want to make sure that the filter does not apply only the first letter in the numberPassword of the editText. Please give me an answer on what to do. android:inputType="numberPassword" ex -******* -> -3******
  • u

    user

    07/25/2022, 5:41 AM
    OEM Permission Manger I want more informations about OEM permission in android application and how to implement in Automobile AVD and what methods used in OEM permission to use in android automotive AVD
  • u

    user

    07/25/2022, 5:41 AM
    Implementing Flood Fill Algorithm in Kotlin import java.util.Queue import java.util.LinkedList fun explore(row: Int, column: Int) { val length1 = minefield.size val length2 = minefield[0].size if (displayedMinefield[row][column] == "/") return val queue: Queue = LinkedList() queue.add(listOf(row, column)) while (!queue.isEmpty()) { val (i, j) = queue.first queue.removeFirst() if (i < 0 || i >= length1 || j < 0 || j >= length2) { continue } else { if...
  • u

    user

    07/25/2022, 6:21 AM
    sequence concatadapter based on data type is it possible to use concatadapter based on data type. normal implementation of concatadapter is val concatadapter = listOf(firstAdapter, secondAdapter, thirdAdapter) while trying this code, for (nums in 0..15) { if (nums % 2 == 0) { concatAdapter.add(firstAdapter) } else { concatAdapter.add(secondAdapter) } } the first "firstAdapter" and "secondAdapter" will be display. But the next "firstAdapter" and "secondAdapter" is not displayed. is there...
  • u

    user

    07/25/2022, 7:41 AM
    Will the operation of collect from Flow cost many system resources when I use Compose with Kotlin? The SoundViewModel is a ViewModel class, and val listSoundRecordState may be used by some modules in the App. In Code A, I invoke fun collectListSoundRecord() when I need to use the data listSoundRecordState. But fun collectListSoundRecord() may be launched again and again because of Jetpack Compose recomposition, I don't know if it will cost many system resources? In Code B, I launch private fun collectListSoundRecord() in init { }, collectListSoundRecord() will be launched only one time,...
  • u

    user

    07/25/2022, 7:41 AM
    How can I handle java.io.EOFException? The error came up in the QR Scan Fragment that I created, when I finished scan, the error said D/StompClient: Socket closed with error Below are the list of error:- java.lang.Exception: java.io.EOFException at ua.naiksoftware.stomp.provider.OkHttpConnectionProvider$1.onFailure(OkHttpConnectionProvider.java:84) at okhttp3.internal.ws.RealWebSocket.failWebSocket(RealWebSocket.java:570) at okhttp3.internal.ws.RealWebSocket$1.onResponse(RealWebSocket.java:211)...
  • u

    user

    07/25/2022, 8:01 AM
    How to count unique csv/parquet rows? Is there a better algorithm for counting unique rows in csv/parquet than writing to HashMap or reading one row and iterating through whole file(if file is big)?
  • u

    user

    07/25/2022, 8:21 AM
    How to make certain part of an activity change depending on the day of the week? ANDROID STUDIO I am using a HorizontalScrollView as a container, inside it I have a button for each day of the week (Monday, Tuesday..., Friday) I want that depending on the day of the week when opening the application it automatically scrolls there, that is, today it is Monday the button that appears as an option is "MONDAY", if it is Wednesday the first option that appears is WEDNESDAY. <a href="https://i.stack.imgur.com/BQpWJ.png" rel="nofollow noreferrer">HorizontalScrollView, contains the different...
  • u

    user

    07/25/2022, 9:01 AM
    Can i use an interface type as constructor parameter in Koltin Coming from Java, I define two interfaces for triangles: interface TriangleA { val side: Double val corner1: Double val corner2: Double } interface TriangleB { val side1: Double val side2: Double val side3: Double } Then I define an adapter class that accepts a TriangleB and exposes a TriangleA class TriangleBAdapter(triangleB:TriangleB):TriangleA{ override val side: Double get() = this.triangleB.side override val corner1: Double...
  • u

    user

    07/25/2022, 9:21 AM
    kotlinOptions.useIR = true causes error after upgrade to Kotlin 1.7.10 I received a notification from android Studio to update my app to Kotlin 1.7.10. (all is working well at Kotlin 1.6.21) When I did that, I started receiving an error for the line kotlinOptions.useIR = true (I previously put this in about a year ago when I removed apply plugin: 'kotlin-android-extensions' which I was told at the time was bad, and at the same time added in buildFeatures { viewBinding = true } ) The error I receive for the useIR line is:
    No such property:...
  • u

    user

    07/25/2022, 9:21 AM
    Draw a circle in a fixed area on the mapbox map. || Kotlin I've created an app I've used geofence I want. Show a circle on the mapbox with the same radius as the geofence. The problem is that the circle is displayed and the size of the circle changes as the map is zoomed.
  • u

    user

    07/25/2022, 9:21 AM
    Spotify AUTHENTICATION SERVICE UNKNOWN_ERROR kotlin android I am trying authenticate user with spotify app and spotify auth API (implementation 'com.spotify.android:auth:2.0.1') followed the steps mentioned in Spotify SDK github sample my code: Added in gradle(app.module) defaultConfig { manifestPlaceholders = [redirectSchemeName: "appname", redirectHostName:"spotify_login_callback"] } // Fragment/Activity val CLIENT_ID = "7bf56252cd644b339cc97df5b4d7eeee" val AUTH_TOKEN_REQUEST_CODE = 0x10 val AUTH_CODE_REQUEST_CODE = 0x11 var mAccessToken: String?...
  • u

    user

    07/25/2022, 9:41 AM
    Kotlin coroutines in Minecraft spigot plugin In the docs it says that coroutines are lighter than threads and so I wanted to use a kotlin coroutine instead of the BukkitRunnable. //Defined as class field private val scope = coroutineScope(Dispatchers.Default) //In class method scope.launch {/* wait some seconds and then change blockdata */} Calling setBlockData from Dispatchers.Default thread throws an error because the spigot API is not thread safe and you can't call API stuff from another thread(from what I understand). I was...
Powered by Linen
Title
u

user

07/25/2022, 9:41 AM
Kotlin coroutines in Minecraft spigot plugin In the docs it says that coroutines are lighter than threads and so I wanted to use a kotlin coroutine instead of the BukkitRunnable. //Defined as class field private val scope = coroutineScope(Dispatchers.Default) //In class method scope.launch {/* wait some seconds and then change blockdata */} Calling setBlockData from Dispatchers.Default thread throws an error because the spigot API is not thread safe and you can't call API stuff from another thread(from what I understand). I was...
View count: 3