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/16/2022, 8:21 AM
    Check if app's in foreground or background I want to update user status in firestore to online and offline according to whether the app runs in the background or foreground. I'm using LifecycleObserver for it, but the problem is I have to call it in every single activity for it to work. Is there a way to do this without having to call it in every activity? Observer class: class Observer(private val currentUser: User): LifecycleObserver { @OnLifecycleEvent(Lifecycle.Event.ON_START) fun onEnteredForeground() { if...
  • u

    user

    07/16/2022, 8:41 AM
    How to pass extension function as argument? There is an extension functions fun List.sortByTitle(): List { return this.sortedBy { it.title } } fun List.sortByArtist(): List { return this.sortedBy { it.artists[0].name } } What need to write in arguments of sort function in order to pass an extension function? fun sortByTitle(owner: String, kind: String) { sort(owner, kind) // pass List.sortByTitle } fun sortByArtist(owner: String, kind: String) { sort(owner, kind) // pass List.sortByArtist } private fun sort(owner:...
  • u

    user

    07/16/2022, 8:41 AM
    Why is ByteBuffer.get(byte[] dst, int offset, int length) so fast? The documentation says : public ByteBuffer get(byte[] dst, int offset, int length) Relative bulk get method. This method transfers bytes from this buffer into the given destination array. If there are fewer bytes remaining in the buffer than are required to satisfy the request, that is, if length > remaining(), then no bytes are transferred and a...
  • u

    user

    07/16/2022, 9:21 AM
    I'm having trouble linking a profile in my contacts app I created the contacts and profile interface in my contacts application that I have been working on for a while. However, I was stuck in the section of going to the profile of the person I clicked on my contacts that I designed with listview. I am waiting for support from my friends who understand Kotlin well. [1]:

    https://i.stack.imgur.com/8oFMg.png▾

    [2]: <a href="

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

    " rel="nofollow...
  • u

    user

    07/16/2022, 9:21 AM
    How to check all of items in Android I want develop test application and for this I want use this API : https://www.themealdb.com/api/json/v1/1/lookup.php?i=52772 In this API for show some info use many field, such as strIngredient1,strIngredient2,strIngredient3 and more to strIngredient15. I want first check each of this items, and when not empty. then show this. There are 15 items and I don't want check each of items! I want...
  • u

    user

    07/16/2022, 9:41 AM
    I have a problem with Simple Android Activity Lifecycle Could you explain me, why both of my Android 12 and Android 8 does not call method onSaveInstanceState() class MainActivity : AppCompatActivity() { private lateinit var binding: ActivityMainBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMainBinding.inflate(layoutInflater).also { setContentView(it.root) } Log.d("AAAAA", "onCreate") binding.buttonSet.setOnClickListener {...
  • u

    user

    07/16/2022, 10:21 AM
    Applying a style/theme to one module only I'm creating a first multi-module application, which consists of 4 modules: app domain data presentation the app module contains it's own separate "themes.xml", but I cannot use that inside of presentation module (cause it is not a shared module, and I don't want to make it a shared module) Is there a way to create a separate themes only for the presentation package? and how does one apply it to a fragment?
  • u

    user

    07/16/2022, 10:21 AM
    LocationServices.getFusedLocationProviderClient(Activity()) - Attempt to invoke virtual method 'getApplicationContext()' on a null object reference I'm building an android app which using a map fragment. Lately I redesigned my app and moved the map view to a fragment. everything worked before, I'm asking for permissions and manifest has the parent activity of the current fragment. While I'm trying to get fused location provider as following: override fun onMapReady(googleMap: GoogleMap) { mMap = googleMap mFusedLocationClient = LocationServices.getFusedLocationProviderClient(Activity()) } I'm getting:...
  • u

    user

    07/16/2022, 10:21 AM
    Page crashes after splashscreen I am developing an application with jetpack compose. The interface was working, today I wrote the necessary codes to make transactions using the room database. After adding the database codes to the relevant fields in the panel page, the application crashes after splashscreen. I couldn't find the error. Since the codes are long, I share the codes on the github page. Mainactivity class MainActivity : ComponentActivity() { @DelicateCoroutinesApi override fun...
  • u

    user

    07/16/2022, 10:41 AM
    Adding spacing between BottomNavigationItem's icon &amp; label I'm trying to build out my Bottom navigation like this: @Composable fun BottomNavBar(navController: NavController) { Column( Modifier.background(colorResource(id = R.color.pastel_orange_white)) ) { BottomNavigation( modifier = Modifier .defaultMinSize(minHeight = 70.dp), backgroundColor = colorResource(id = R.color.bottom_nav_dark) ) { val navItems = arrayOf( BottomNavItem(...
  • u

    user

    07/16/2022, 10:41 AM
    Android linking Faild ERROR:C:\Users\aron.kibet\AndroidStudioProjects\Status_Saver22\app\src\main\res\layout\activity_main.xml2️⃣ AAPT: error: attribute layout_height (aka com.example.status_saver22:layout_height) not found.
  • u

    user

    07/16/2022, 10:41 AM
    Kotlin Client send and receive image from Linux python3 socket Server I'm trying to send and receive Image with Socket connect However, the string between the client and the server can be exchanged, but it does not proceed from exchanging images. This is My Kotlin Client code class MainActivity : AppCompatActivity() { lateinit var binding: ActivityMainBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMainBinding.inflate(layoutInflater) setContentView(binding.root)...
  • u

    user

    07/16/2022, 11:01 AM
    Kotlin not making request Volley - android I am trying to "dynamically" create CardView and then fill TextView with data from an API call. The thing is, to me it seems like the request is not getting called. I created an adapter class based on Create dynamically lists with RecyclerView which is working fine and I am adding as many windows as needed. And then in the MainActivity, I am trying to do an API request with Volley. Before...
  • u

    user

    07/16/2022, 11:01 AM
    How do I create an application using kotlin command? [closed] When a user types the Kotlin code, the output is printed Is there any suggestion about this?
  • u

    user

    07/16/2022, 11:01 AM
    How to change the selected recyclerview item position to the first position and background colour here I change the selected item position and set that item to the first position init var selectedItemPos = -1 holder.itemView.setOnClickListener { selectedItemPos = position Collections.swap(dataset,0,position) notifyDataSetChanged() } if (selectedItemPos == position) holder.itemView.setBackgroundColor(Color.parseColor("#200f726b")) else...
  • u

    user

    07/16/2022, 12:21 PM
    How to call suspend function on init? I'm a bit lost here, I dont quite get how suspend functions work yet so any tips or fix for this one? init: init { val settings = FirebaseFirestoreSettings.Builder() .setCacheSizeBytes(FirebaseFirestoreSettings.CACHE_SIZE_UNLIMITED) .build() db.firestoreSettings = settings credentials = getCredentials() // Throws 'Suspend function 'getCredentials' should be called only from a coroutine or another suspend function' } Suspend function: // ... this function is...
  • u

    user

    07/16/2022, 12:41 PM
    CountDownTimer in Android ViewModel executes onFinish twice I tried to implement a timer in a ViewModel that after ten seconds returns to the previous view, but it doesn't work at all. I wonder if CountDownTimer can even be used in a ViewModel. class PairingScreenViewModel( private val routing: NavController, ) : ViewModel() { var content = mutableStateOf(10) var counter: CountDownTimer? = null init { viewModelScope.launch { delay(1000L) counter = object : CountDownTimer(9000L, 1000L) {...
  • u

    user

    07/16/2022, 1:21 PM
    Jetpack Compose: Reading and storing Byte array from a URL stream in a Coroutine scope I am trying to use the Android MLKit text recognition tool to read the text in an image from the internet. It requires an InputImage object, and I want to create one using the fromByteArray method. I planned on opening a URL stream and reading it into a Byte array, in the code below. But I got a...
  • u

    user

    07/16/2022, 1:41 PM
    compileReleaseJavaWithJavac' task (current target 1.7) and 'compileReleaseKotlin' task (current target 1.8) jvm target compatibility should be same I'm Using a third party library as a jar download in my project called "bandlibrary". Getting following error. [root@ip-172-31-23-189 hsandroidconsumer]# ./gradlew assembleABCRelease Configuration on demand is an incubating feature. Configure project :app Warning: The 'kotlin-android-extensions' Gradle plugin is deprecated. Please use this migration guide (<a href="https://goo.gle/kotlin-android-extensions-deprecation" rel="nofollow...
  • u

    user

    07/16/2022, 2:01 PM
    testing Repository class that takes DAO parameter I am learning Kotlin to build a note app. I have created a repository class as shown below which takes a Dao parameter. For now, the source of data is just Dao but in the tutorial I am following, it calls an API class as well. What I want to know is how do I test a repository classes logic? import androidx.lifecycle.LiveData import com.example.lastnotetakingapp.db.daos.NoteDao import com.example.lastnotetakingapp.db.models.Note class NotesRepo(private val notesDao: NoteDao) { val...
  • u

    user

    07/16/2022, 2:41 PM
    I can't redirect to another page when I click on listview I'm designing a phone book application, I've done most things, but I can't go to the profile of the person whose name I clicked. I would appreciate if you explain the use of setOnListener in detail. class MainActivity : AppCompatActivity() { var listView: ListView? = null lateinit var binding: ActivityMainBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMainBinding.inflate(layoutInflater)...
  • u

    user

    07/16/2022, 3:21 PM
    Animate canvas items that are based on a constantly changing list state TL;DR: How would I animate multiple item heights within the Canvas. Like the height of these spikes in a waveform. A little back story: I'm writing an app to display the waveform of an ongoing audio recording. I'm taking the bytes directly from an AudioRecord and calculating the amplitude every 1000ish samples and pushing them to a list that is then observed in a composable. The usage within the composable looks something...
  • u

    user

    07/16/2022, 4:01 PM
    Kotlin Multiplatform multi-project Gradle error: "Projects must be configuring" I have a Kotlin Multiplatform project (1.7.10), with multiple subprojects, using Gradle 7.4.2. When running Gradle tasks I regularly get an error message from the Kotlin Gradle plugin: * What went wrong: Execution failed for task ':modules:web-map:publicPackageJson'.
    Error while evaluating property 'externalDependencies$kotlin_gradle_plugin' of task ':modules:web-map:publicPackageJson'
    > Projects must be configuring The error will not go away, unless I somehow force the project to...
  • u

    user

    07/16/2022, 4:21 PM
    Haskell equivalent of Kotlin's invariant types In Kotlin i can do sealed class Substance { object Uranus : Substance() object Mercury: Substance() object Ammonia : Substance() } data class DangerousBox(val item: T) fun main() { val uranus = DangerousBox(Substance.Uranus) val mercury: DangerousBox = uranus } Now i have invariant types DangerousBox, DangerousBox etc., so sample above would't compile. How make it in Haskell? Ideally i would like to have types uranus :: DangerousBox Uranus uranus = DangerousBox Mercury...
  • u

    user

    07/16/2022, 4:21 PM
    Build script-is it a build gradle Caused by: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
  • u

    user

    07/16/2022, 4:41 PM
    Kotlin filter nested lists I want to filter a list that has episodes of series. The list looks a bit like this: [ { "media": { "episode_number": "7" }, "collection": { "collection_id": "26464" } }, { "media": { "episode_number": "6" }, "collection": { "collection_id": "26464" } }, { "media": { "episode_number": "9" }, "collection": { "collection_id": "123456" } } ] I only want the highest episode number of each collection...
  • u

    user

    07/16/2022, 5:01 PM
    How to send empty string on query parameter retrofit kotlin I have an API URL like https://api.github.com/search/users?q="", so I try to hit it with the postman, and it is fine.

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

    And then I want to implement that request using retrofit. So I create an Query Parameter on retrofit, like this, @GET("search/users") @Headers("Authorization: token ${BuildConfig.TOKEN}") fun searchUser(...
  • u

    user

    07/16/2022, 5:41 PM
    Gradle Sync: "Cannot find a variant matching build type 'null' and product flavors '[]' in module" [AGP] There's a syncing problem that only appears while trying to use Android Gradle Plugin version 7.2.0 and above; So, the sync is successful with AGP 7.1.3, but fails with 7.2.1 or even 7.4.0-alpha08. The project is a KMP project, but for the above reason, I assume the issue is related to AGP and its configuration. Project Structure The project's android target follows the modular architecture described below: ┌─────────────┐ Depends On ┌────┐ ┌────┐ ┌─────────────┐ │ :androidApp │...
  • u

    user

    07/16/2022, 6:21 PM
    java.lang.ClassCastException for currency conversion class I'm using Ktor client to get currency conversion rates, the Json response I get starts like this BODY START { "result":"success", "documentation":"https://www.exchangerate-api.com/docs", "terms_of_use":"https://www.exchangerate-api.com/terms", "time_last_update_unix":1657929601, "time_last_update_utc":"Sat, 16 Jul 2022 00:00:01 +0000", "time_next_update_unix":1658016001, "time_next_update_utc":"Sun, 17 Jul 2022 00:00:01 +0000", "base_code":"USD", "conversion_rates":{ "USD":1, "AED":3.6725,...
  • u

    user

    07/16/2022, 6:41 PM
    Does Dagger support multibinding with KClass&lt;*&gt; type? I have a KeyMap like this: @Target(AnnotationTarget.FUNCTION) @MapKey annotation class JsonSerializerKey(val value: KClass) and want to provide them as: // #1 doesn't work Map // #2 works Map Dagger can't find and collect provided items when requesting KClass (with below error) but it works with Class. error: [Dagger/MissingBinding] java.util.Map> cannot be provided without an @Provides-annotated method. How can I achieve map of KClass in dagger multibinding? P.S: All provided...
Powered by Linen
Title
u

user

07/16/2022, 6:41 PM
Does Dagger support multibinding with KClass&lt;*&gt; type? I have a KeyMap like this: @Target(AnnotationTarget.FUNCTION) @MapKey annotation class JsonSerializerKey(val value: KClass) and want to provide them as: // #1 doesn't work Map // #2 works Map Dagger can't find and collect provided items when requesting KClass (with below error) but it works with Class. error: [Dagger/MissingBinding] java.util.Map> cannot be provided without an @Provides-annotated method. How can I achieve map of KClass in dagger multibinding? P.S: All provided...
View count: 3