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/07/2022, 8:31 PM
    Upload image File from file path In android studio I have uploaded an image to the drawables folder in resources and not I'm trying to use that image in my project. Im checking to make sure the image file exists, but checking if it exists returns false everytime val imgFile = File("/Users/jakesmith/Desktop/Attachments/app/src/main/res/drawable/myimage.png") if (imgFile.exists()) { val myBitmap = BitmapFactory.decodeFile(imgFile.absolutePath) imageView.setImageBitmap(myBitmap)...
  • u

    user

    07/07/2022, 9:51 PM
    Navigate from one Activity to another one in multi module app The scheme of my app could be something like this

    https://i.stack.imgur.com/wXVbt.png▾

    core - It has all the base code for the entire project. app - Check if the user has the session active and then navigate to :ft_main or to :ft_auth. ft_main - It has a list of items for a specific user. ft_auth - It has all the logic to log in and sign up. PROBLEM As app known about all the libraries, I could include the navigation graph on my app's navigation graph...
  • u

    user

    07/07/2022, 11:11 PM
    Copiar valor de atributo de um objeto para outro dentro de uma lista Estou com dificuldade em conseguir copiar um atributo dentro de um objeto page para outra objeto que está numa lista. No código abaixo, ele me retorna uma lista vazia, na verdade preciso iterar minha primeira lista chamada cars e comparar o id dela com o id da lista travelHistory, se o id for igual, copiar o valor de count da segunda lista para a primeira lista. private fun addTravelHistory(cars: Page): Page { val travelHistory = getTravelHistory( car.map { it.id }.get().toList()...
  • u

    user

    07/07/2022, 11:31 PM
    Having trouble using API Key with retrofit get request I am new to retrofit. I need to use an API key to access this API to retrieve country data. I have placed my API key inside the header in place of MY_API_KEY. interface CountryApi { @Headers("api-key: MY_API_KEY") @GET("all") suspend fun getCountryData(): List } I get the following error when I run the project. 2022-07-07 18:27:31.768 6035-6035/com.example.countryapp1 E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.countryapp1, PID: 6035 retrofit2.HttpException:...
  • u

    user

    07/08/2022, 12:11 AM
    Android Studio (Kotlin): Error ehen starting the debugger I am a novice at Android and Kotlin, and I've started to follow the "fundamentals" codelabs. I also have an experimental app of my own that I wrote from scratch. It runs nicely on the emulator and the device, but now I can no longer run it in the debugger (using the "bug" icon). When I do that, I immediately get this stack trace: access:-1, Linux (libcore.io) access:131, ForwardingOs (libcore.io) access:76, BlockGuardOs (libcore.io) access:131, ForwardingOs (libcore.io) access:7719,...
  • u

    user

    07/08/2022, 12:11 AM
    How do I set a default Answer strategy with Mockk In Mockito, I can create a mock of a class, and specify the default answer for any function calls to that mock, like this: whenever(this.strings).thenReturn(mock(StringProvider::class.java, StringProviderAnswer())) Where the answer might be class StringProviderAnswer : Answer { private val delegate = Mockito.RETURNS_DEFAULTS!! override fun answer(invocation: InvocationOnMock?): Any? { val invocationMethodReturn = invocation?.method?.returnType val stringType =...
  • u

    user

    07/08/2022, 2:11 AM
    Material Dialog suddenly closes when going to another activity in Android Kotlin I have a material dialog inside onForegroundStart() in my BaseActivity. I have extended all my Activities in BaseActivity and opening an app will go to SplashActivity -> HomeActivity if the user is logged in. However, I have noticed that the dialog will suddenly closes when going to another activity. Is there anything that I have missed? @OnLifecycleEvent(Lifecycle.Event.ON_CREATE) fun onCreate() { if (isLoggedIn()) { dialog = MaterialDialog(this) .show...
  • u

    user

    07/08/2022, 2:51 AM
    React Native: 'compileJava' task(current target is 1.8) and 'compileKotlin' task(current target is 11) jvm target compatibility problem I am new to the React Native development with using Mac M1. When I was running React Native Android, I got the errors below. I really have no idea how to fix this error, Appreciate if anyone could help, thanks again!
    Task :react-native-gradle-plugin:compileKotlin
    'compileJava' task (current target is 1.8) and 'compileKotlin' task (current target is 11) jvm target compatibility should be set to the same Java version.
    Task :react-native-gradle-plugin:compileKotlin FAILED
    Deprecated Gradle...
  • u

    user

    07/08/2022, 3:51 AM
    Android Navigation Component not saving fragment state with BottomNavigationView I'm using Navigation fragment version 2.5.0. As release of version 2.4.0-alpha01, it's suppose to support back stack support for bottom navigation without writing any additional code. But my fragments are re-created everytime while I navigate with bottom navigation. I'm using single graph, single activity Architecture. Navigation dependencies implementation 'androidx.navigation:navigation-fragment-ktx:2.5.0' implementation 'androidx.navigation:navigation-ui-ktx:2.5.0' Nav-controller val...
  • u

    user

    07/08/2022, 5:11 AM
    android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.location/java.lang.String}; I working on a flutter project which uses location services. There is one case where user 'denied permission forever', that time i need to open app location setting to turn it on and for that i'm using native code of kotlin. all code of native is working fine (checking using Log) but on startActivity(Intent(this, Settings.ACTION_LOCATION_SOURCE_SETTINGS::class.java)) it does not open that app location setting page and says the error android.content.ActivityNotFoundException: Unable to find...
  • u

    user

    07/08/2022, 5:31 AM
    The property 'window' can't be unconditionally accessed because the receiver can be 'null' This error appears on my flutter app after connecting it to the firebase. Not really sure if that has something to do with the cause of the error. here is the code Size size = WidgetsBinding.instance.window.physicalSize / WidgetsBinding.instance.window.devicePixelRatio; ///This method is used to set padding/margin (for the left and Right side) & width of the screen or widget according to the Viewport width. double getHorizontalSize(double px) { return px * (size.width / 360); }...
  • u

    user

    07/08/2022, 5:31 AM
    How to generate android resource (xml) files by using Kotlin KSP I'm working on a custom generator to generate code from annotation on Android platform. I currently using KSP for code generating. After I generate the code, I need to generate some resource xml files, What shall I do for it? I considered some points: There are official way to generate resource file in build.gradle, but because the content of the resource is derived from the annotation so I can't move the generator code to build.gradle. Another way is move the generator code to build.gradle...
  • u

    user

    07/08/2022, 5:51 AM
    How do I iterate over return type of Either<ClientError, List<Employee>>? Lets say my function A is returning Either. I assign it to a variable lets say: val employeeList = A(). for (e in employeeList) gives me an error saying "for loop must have iterator". How do I overcome this?
  • u

    user

    07/08/2022, 8:11 AM
    How to add a button at the end of a recycler view (kotlin)? I'm gonna add a button at the end of my recycler view and i don't know how to do it . i will appreciate you if you teach me . this is my main activity code : class MainActivity : AppCompatActivity() { private var number: Int = 0 private lateinit var name: String override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val myRecyclerView = findViewById(R.id.recyclerView) val myViewModel = ViewModel()...
  • u

    user

    07/08/2022, 8:11 AM
    I need to Control the bottom sheet swipe area in Kotlin

    enter image description here▾

    I had a webview in bottom sheet. I'm showing pdf file in webview. While user try to zoom pdf the bottom sheet's swipe is working to. I want to swipe down the bottom sheet with only thouching the head of the bottom sheet.
  • u

    user

    07/08/2022, 8:51 AM
    Problem with updating compose version to 1.3.0-alpha01 I have an Android Studio project that works fine when I'm using Kotlin version 1.6.21 and compose version 1.2.0-rc01. The problem arises when I want to update both dependencies to the latest versions, which are 1.7.10 for Kotlin and 1.3.0-alpha01. The error that I get is: Could not resolve all files for...
  • u

    user

    07/08/2022, 8:51 AM
    Android Room: "Each bind variable in the query must have a matching method parameter" I'm using room database for android. It was working fine until I updated to Kotlin 1.7.0 recently. Now I get the following error: Each bind variable in the query must have a matching method parameter. Cannot find method parameters for :limit, :offset. Here is my dao: @Query("SELECT * FROM eventdata ORDER BY id ASC LIMIT :limit OFFSET :offset") fun allEvents(limit: Int, offset: Int): List Here my build.gradle apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin:...
  • u

    user

    07/08/2022, 9:11 AM
    Generic "checkType" function with args as parameter, but I don't know how to make it able to the value type according to attached parameters Example input: checkType(10) output: "Yes! it's Integer" Here are some mandatory value types: Integer String Boolean Double List Map fun checkType(args: T): String { return "" } fun main() { println( """ '[10, 9, 8 , 6]' is List? ${checkType(listOf(10, 9, 8, 6))} 'This is Koltin' is String? ${checkType("This is Kotlin")} 'True' is Boolean? ${checkType(true)} '10.01' is List? ${checkType(10.01)} """.trimIndent() ) }
  • u

    user

    07/08/2022, 9:31 AM
    Validate consistency between open api apec and code I have open-api.yaml where I describe my api spec. I have a code where I implement the spec. I'm not sure about using auto-generating code by spec because: I'm not sure that it will work good with null-safety I use 'type-safety' pattern for some fields instead of just using primitive type and don't know how continue to use it: data class SpecificValue @JsonCreator(mode = d) constructor(@JsonValue val value: String) { override fun toString() = value } So I have to implement my spec in...
  • u

    user

    07/08/2022, 9:31 AM
    Spring @RestControllerAdvice doesn't handle status code 400 exceptions I have the following class for handling rest controller exceptions @RestControllerAdvice class RestResponseEntityExceptionHandler : ResponseEntityExceptionHandler() { @ExceptionHandler( value = [ (NotFoundException::class), (AccountNotFoundException::class), (ExecutionLogNotFoundException::class), (SubscriptionNotFoundException::class) ] ) protected fun notFoundException( ex: Throwable?, request:...
  • u

    user

    07/08/2022, 9:51 AM
    Is there a way in which we can swipe the recycler view all the item at once on button click with the help of ItemTouchHelper? There is button in which user can tap then all the recycler view item get swiped at once. And also have capability of manual swipe on recycler view item.
  • u

    user

    07/08/2022, 10:11 AM
    Complete the function initialization with the return value of Map below with the following key-values Complete the function initialization with the return value of Map below with the following key-values: key: type value: car key: maxSpeed value: 300Km/s key: maxTank value: 75Ltr fun vehicle() = mapOf() fun main() { println(""" My Map Result: ${vehicle()} """.trimIndent()) }
  • u

    user

    07/08/2022, 10:11 AM
    What graphic element is this? Hi I should implement a filter in a recyclerview graphically I wanted to introduce such a thing but what element is it? a spinner? if yes how can i make it similar to this play store example thank you

    https://i.stack.imgur.com/58eIO.png▾

    https://i.stack.imgur.com/uxTqi.png▾

  • u

    user

    07/08/2022, 10:11 AM
    How can I get data from API response in kotlin [closed] just wondering how can i get the data from "other_items" in kotlin. Thank you

    https://i.stack.imgur.com/V338l.png▾

  • u

    user

    07/08/2022, 11:31 AM
    how can I consume LiveData<PagedList<Letter>> in a dataRopsitory from an Application class? I'm working on a feature for a letter vault project that helps keeps a letter till a latter time you want it opened...the idea is that the user receives a notification once a letter is ready to be opened. I have a function in the DataRepository that helps letter from the database with the help of paging library. class DataRepository(private val letterDao: LetterDao) { companion object { const val PAGE_SIZE = 30 const val PLACEHOLDERS = true private val PAGING_CONFIG =...
  • u

    user

    07/08/2022, 11:31 AM
    Why do I need to wrap navActions.navigateToPurchase() with LaunchedEffect in fun NavGraph when use Jetpack Compose? In my plan, I hope to display Home UI when I run an app first, a user can open Purchase UI by clicking a button on Home UI. And more, Purchase UI will be displayed automatically if the app is expired when I run the app first. In Code A, navActions.navigateToPurchase() is invoked in both fun NavGraph(...) and fun ScreenHome(...). The app will crash if I don't wrap navActions.navigateToPurchase() with LaunchedEffect in fun NavGraph(), why? You can see Error Logs below. Code A @Composable fun...
  • u

    user

    07/08/2022, 11:51 AM
    How i can update document in Firestore kotlin? I want to update or merge Firestore document without adding new document. So i want to image url to firestore existing document field with merge method. But it does not overwrite, it is going to create a new document with auto-generated ID. How i can fix it? val uuid = UUID.randomUUID() val imageName = "$uuid.jpg" val reference = storage.reference val imagereference = reference.child("images").child(imageName) if (selectedPicture != null) {...
  • u

    user

    07/08/2022, 12:11 PM
    How to properly register OncePerRequestFilter to check tokens with spring-security 5.7? I am trying to secure a simple webservice with an AuthController providing a login and refresh endpoint. Hence auth/** should be open and all other apis should only be accessible with a valid token. The auth endpoints work, however I have some troubles with the proper security configuration. I implemented the following JwtTokenFilter: class JwtTokenFilter() : OncePerRequestFilter() { @Autowired private lateinit var jwtTokenService: JwtTokenService @Autowired private lateinit...
  • u

    user

    07/08/2022, 12:31 PM
    Android kotlin migration in library module "Cannot change attributes of dependency configuration '<xxx>:debugCompileOnly' after it has been resolved" I have started to migrate from Java to Kotlin for a project. It consists of 3 library modules, ui-core, ui-xxx, and ui-yyy, and an application submodule demo. The migration from Java to Kotlin in the application submodule was relatively easy and is done. I have done the Kotlin migration from another library project already, so I know it's not different than an application module. Root level build.gradle: buildscript { ... repositories { maven { ... } } dependencies {...
  • u

    user

    07/08/2022, 12:31 PM
    Null safety in Kotlin for MutableMap with MutableList I am trying to run this example fun main() { val mlist: MutableList = mutableListOf() val mapp: MutableMap = mutableMapOf(1 to mlist) println(mapp) mapp[1].add("a") // Correct is mapp[1]?.add("a") println(mapp) } at Online Kotlin Compiler. The compiler is complaining about Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type MutableList?. Although I have defined...
Powered by Linen
Title
u

user

07/08/2022, 12:31 PM
Null safety in Kotlin for MutableMap with MutableList I am trying to run this example fun main() { val mlist: MutableList = mutableListOf() val mapp: MutableMap = mutableMapOf(1 to mlist) println(mapp) mapp[1].add("a") // Correct is mapp[1]?.add("a") println(mapp) } at Online Kotlin Compiler. The compiler is complaining about Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type MutableList?. Although I have defined...
View count: 4