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/11/2022, 5:31 PM
    Kotlin, How do I make a function for distinctBy method Suppose, I have this list which contains a list of employee info. val distinctEmployee = employees.distinctBy { it.firstName } I want to make a function and pass as a parameter for distinctBy method so I can apply any kind of distinct method to the list. I expect something like this. val highSalaryEmployee = employees.filterBy(salaryFilter) function salaryFilter(employee: Employee): Boolean { return employee.salary > 350000 } I have done this with filterBy method before, but I dont know...
  • u

    user

    07/11/2022, 5:51 PM
    how can remove text in html use jsoup java I want to remove the existing text And replace it with another text and then publish it html fun main() { println("Hello World") }
  • u

    user

    07/11/2022, 6:31 PM
    Jetpack Compose - mutableStateOf() not updating I got a ScreenState data class in my ViewModel: data class ScreenState( var isLoading: Boolean = true, val items: List = emptyList() ) and a mutableStateof: private val _homeScreenState = mutableStateOf(ScreenState()) val homeScreenState: State = _homeScreenState Updating the isLoading property works fine, the change gets send to my UI: _homeScreenState.value = _homeScreenState.value.copy(isLoading = true) But updating an item inside my List does not work. Here is how I try to do...
  • u

    user

    07/11/2022, 7:11 PM
    How can i set up Download Button that download an apk via Link? How can i set up Download Button that download an apk via Google Drive Link? Sample Code MainActivity.java: package com.example.project; public class VersionActivity extends AppCompatActivity
  • u

    user

    07/11/2022, 7:31 PM
    How to inject dependency in composable using dagger hilt Maybe I'm blind but I can't find anything about injecting a dependency that needs parameters in side a composable using dagger hilt. Lets say my ViewModel looks something like this: class MyViewModel @AssistedInject constructor(@Assisted myValue: Int) : ViewModel() { ... } and I've got a factory interface like this: @AssistedFactory interface MyViewModelAssistedFactory { fun create(myValue: Int): MyViewModel } how can I inject that dependency with a certain value as parameter? All...
  • u

    user

    07/11/2022, 8:11 PM
    Kotlin/AndroidStudio - problem with connect listView with RecyclerView I’m still learning and I see that there’s a long way ahead of me. However I got stuck with my app and I can’t find any clues online so I need your help. I have a problem with connect listView with RecyclerView: in the first ACTIVITY I have a list and after selecting the first position, my intention was that it should return a FRAGMENT with recycler view (and cardView). Unfortunately I try a lot of methods but I still don’t know the solution. Anyone help me, please? 😊 Animal Habitats class...
  • u

    user

    07/11/2022, 8:31 PM
    Use multiple variables in single string interpolation kotlin

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

    How should can I use multiple var in single ${} fun main() { var a = 5 var b = 20 if (b % a == 0 && b > a++) print("statement 1st - ${a--, --b}") if (a % 5 == 0 || a >= b++) print("statement 2nd - ${a--, --b}") }
  • u

    user

    07/11/2022, 9:11 PM
    Question about launchWhenX and repeatOnLifecycle I have the following code and a few questions that need to be answered: override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) lifecycleScope.launchWhenResumed { delay(2000) Log.d("LifeCycleAware", "launchWhenStarted: before calling") val result = differentDispatcher() Log.d("LifeCycleAware", "launchWhenStarted: after calling $result") } } private suspend fun...
  • u

    user

    07/11/2022, 9:11 PM
    Kotlin NoSuchMethodError after installing a library that enables a plugin I want to experience a library called arrow analysis My build.gradle.kts file looks as follows: import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { kotlin("jvm") version "1.7.10" } group = "org.example" version = "1.0-SNAPSHOT" repositories { mavenCentral() } dependencies { testImplementation(kotlin("test")) implementation("io.arrow-kt:arrow-core:1.1.2") } buildscript {...
  • u

    user

    07/11/2022, 9:31 PM
    How can to create a curved Text around a Canvas I'm beginner in jetpack compose, especially in Canvas. I want to create this with Canvas:

    https://i.stack.imgur.com/wTnH8.jpg▾

    But I don't know how. I could create curved Text but with fillMaxSize and it's not useful for me. Because I want to use this picture as a button in a page and I have some buttons like this one in one page. So I want to have this Canvas with wrapcontent size. So how can I create that?
  • u

    user

    07/11/2022, 9:31 PM
    Deserializing a generic type using gson in kotlin I have a generic type Animal implemented as a sealed class that can be a Dog or a Cat. sealed class Animal(val typeOfAnimal: String) { data class Dog(val barkVolume: Int): Animal("dog") data class Cat(val hasStripes: Boolean): Animal("cat") } According to http://jansipke.nl/serialize-and-deserialize-a-list-of-polymorphic-objects-with-gson/ you can deserialize an...
  • u

    user

    07/11/2022, 9:31 PM
    Mockito: You cannot use argument matchers outside of verification or stubbing I am trying to run the following simple test in Kotlin using Junit4 and Mockito open class B { lateinit var a: A public fun bFun(value: Int) : Int { return a.aFun(value) } } @ExtendWith(MockitoExtension::class) @RunWith(SpringJUnit4ClassRunner::class) class TestB { @Mock lateinit var a: A @InjectMocks lateinit var b: B @Test fun testB() { `when`(a.aFun(eq(1))).thenReturn(2) assertThat(b.bFun(1) == 2) } } However, I am...
  • u

    user

    07/11/2022, 9:51 PM
    Kotlin Compose global footer view I am trying to show an Ad banner at the bottom which is globally displayed. That means that I want to stick there when I navigate throughout the app. So far I've tried adding the NavHost and the AdView inside a Column, hoping that the navigation with the linked pages will just take the remaining space and the bottom view will stick there. However the NavHost takes the whole screen and the AdView has zero height. When I navigate the second view, the AdView is still inside the view hierarchy...
  • u

    user

    07/11/2022, 10:31 PM
    Unexpected implicit cast to TextView>: layout tag was TextView I have a function that accepts a Map: private fun chooseActiveElement(m: Map) {} This code works: chooseActiveElement(mapOf( 1 to (findViewById(R.id.labelFixNo)) )) But this one (parentheses removed) does not: chooseActiveElement(mapOf( 1 to findViewById(R.id.labelFixNo) )) Unexpected implicit cast to TextView>: layout tag was TextView I'm curious, why are the parentheses necessary and what does the error message mean exactly?
  • u

    user

    07/11/2022, 10:51 PM
    LazyVericalGirld prints index of data rather than value Good day, Currently learning android development by developing a "simple" calculator application. Using the LazyVeritcalGrid, i want to accept string data and display it in a text. the issue i am having is that instead of the actually string to be displayed, i'm getting the index number of the string when i add a .toString to the this is the code below //The list data val data = listOf( "AC", "+-", "%", "\u00F7", "7",...
  • u

    user

    07/11/2022, 10:51 PM
    For Android Developers, Interview Question When only onDestroy is called for an activity without onPause() and onStop()?
  • u

    user

    07/11/2022, 11:11 PM
    Android - LiveData observe not getting update from AndroidViewModel in active Activity I do see quite some questions about this issue but most of them are related to Fragment. I am calling it inside the activity but still not observing any changes. MainActivity.kt: class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val mainViewModel = ViewModelProvider( this,...
  • u

    user

    07/12/2022, 12:51 AM
    Swipe to Refresh But Swiping Up from Bottom Of Screen? in Jetpack Compose I haven't found a question that was exactly what I was asking. The only one I found was from 6 years ago: Android Swipe Up to Refresh ListView When I reach the bottom of a Column of Text lists, I want to be able to swipe up from the bottom of the screen to refresh and load more content of the list view. Bottom to Up. I checked the SwipeRefresh library from Google Accompanist, that library only...
  • u

    user

    07/12/2022, 1:31 AM
    Is this how I initialize a list with values in Kotlin? I want to store a number of counts per value, something like this: value count 0 -> 6 1 -> 2 2 -> 0 3 -> 7 As shown in the example, the values start at 0 and are consecutive integers. I want to initialize all counts with 0, so that I can then increment them. This is what I came up with: val histogram = Array(numBuckets) { 0 }.toMutableList() as ArrayList histogram[2]++ It works, but the initialization feels a bit convoluted. Is there a better way? Is the ArrayList the correct collection...
  • u

    user

    07/12/2022, 1:31 AM
    navigation bar doesn't work after fragment change bottom navigation bar doesn't work at all after I change fragment with supportFragmentManager. binding.addBookSelectBackBtn.setOnClickListener { (context as MainActivity).supportFragmentManager.beginTransaction().replace( R.id.nav_host_fragment_container, AddBookFragment() ).commitAllowingStateLoss() } How can I solve it?
  • u

    user

    07/12/2022, 1:51 AM
    applicationContext.getSystemService(SmsManager::class.java) returning null inside a Service Viewed quite a few similar questions so far, but none ended up a solution. I'm trying to start up a foreground service in order to handle SMS messaging. This service is started when the app is first opened and does work on background threads via kotlin coroutines. This process remains active even when the app has been closed. I'm not too well versed on the various Contexts, but I would have thought applicationContext would exist for the lifetime of the app, but the call I make to get the...
  • u

    user

    07/12/2022, 1:51 AM
    Android should you really use by Lazy in ViewModel as per Docs? This Android doc shows following code: class MyViewModel : ViewModel() { private val users: MutableLiveData by lazy { MutableLiveData().also { loadUsers() } } fun getUsers(): LiveData { return users } private fun loadUsers() { // Do an asynchronous operation to fetch users. } } and I'm wondering if it is really correct to use by lazy or...
  • u

    user

    07/12/2022, 2:11 AM
    How to implement `&&` (overlap) operator of postgres in DynamoDB? How to implement && (overlap) operator of postgres in DynamoDB? Like postgres behaves - select array[1, 2, 3] && array[2, 3]; -> true select array[1, 2, 3] && array[3, 4]; -> true select array[1, 2, 3] && array[4, 5]; -> false
  • u

    user

    07/12/2022, 3:11 AM
    getting image Uri in android i am wanting to grab the image uri, upload it to firebase in order for it to be available there and other users r able to see this image when connecting to the firebase database. only issue is when an image is selected, firstImage is set as content://com.android.providers.media.documents/document/image%3A525 which doesn't have the extension, whether it's .png, etc. the logic below is done in a composable function which is y something like gallery intent isn't used. any insights? var...
  • u

    user

    07/12/2022, 3:11 AM
    add version of app at bottom navigation view is not displayed properly As a lot of people are probably trying to do it, I am trying to add a footer to a navigation view. I did this: This working fine but not in 2 cases: small screen because the linearlayout overlap the menu and also if the keyboard is popped up, it move the layout. Any idea how to make sure that the linear layout with the app version stick to the bottom of the navigation or also below the menu item so it's not...
  • u

    user

    07/12/2022, 3:31 AM
    Price GoogleMaps SDK mobile aplication (2022) I am currently working on a native Android application with kotlin and IOS with swift in which I am integrating the google maps sdk. I am integrating a simple map where a marker will be drawn with a specific coordinate (latitude and longitude). My question is if the google maps sdk has any cost with the mentioned features, I have reviewed the documentation but I am a bit confused. For example in the following <a href="https://mapsplatform.google.com/intl/es/pricing/" rel="nofollow...
  • u

    user

    07/12/2022, 3:31 AM
    IT is base on error while building android studio groovy.lang.MissingPropertyException: Could not get unknown property '32' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
  • u

    user

    07/12/2022, 3:51 AM
    Mock trying to initialize fields I have a class that I am trying to mock and call a method on it - @Component open class CloudStorageService { @Autowired lateinit var s3Client: AmazonS3 fun getSizeOfFirstMatchedObject(bucketName: String, directory: String, prefix: String): Long { val request = ListObjectsRequest().withBucketName(bucketName).withPrefix("$directory/$prefix") val listObjects = s3Client.listObjects(request) val objectSummary = listObjects.objectSummaries.first() val size =...
  • u

    user

    07/12/2022, 5:11 AM
    why don't created tables in kopring? im starting learning kotlin + spring boot, and try create table by jpa but but dont created table in my code, below is my code build.gradle.kts ... dependencies { implementation("org.springframework.boot:spring-boot-starter-data-jpa") implementation("org.springframework.boot:spring-boot-starter-web") implementation("com.fasterxml.jackson.module:jackson-module-kotlin") implementation("org.jetbrains.kotlin:kotlin-reflect")...
  • u

    user

    07/12/2022, 6:11 AM
    android fails to open file using intent ACTION_VIEW. On failure, it makes a toast saying couldn't find item. No error thrown into the logs either here is my current code - /** * takes list of keys and the file to open. decrypts the file and opens it using context it * received as a parameter * @param keyList takes list of keys used for encryption and decryption. * @param safeFile the file to open from safe */ fun openFile( keyList: List, safeFile: SafeFiles, context: Context, layoutInflater: LayoutInflater ) { //FILE TO BE OPENED val decryptedFile = File( Environment.getExternalStorageDirectory(),...
Powered by Linen
Title
u

user

07/12/2022, 6:11 AM
android fails to open file using intent ACTION_VIEW. On failure, it makes a toast saying couldn't find item. No error thrown into the logs either here is my current code - /** * takes list of keys and the file to open. decrypts the file and opens it using context it * received as a parameter * @param keyList takes list of keys used for encryption and decryption. * @param safeFile the file to open from safe */ fun openFile( keyList: List, safeFile: SafeFiles, context: Context, layoutInflater: LayoutInflater ) { //FILE TO BE OPENED val decryptedFile = File( Environment.getExternalStorageDirectory(),...
View count: 3