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/23/2022, 7:21 AM
    Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $ Can you help me what I missed? I am getting this error when clicking the button in my project and trying to print the data into text. Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $ Can you help me what I missed? MainActivity : @AndroidEntryPoint class MainActivity : AppCompatActivity() { private lateinit var binding: ActivityMainBinding private val viewModel: PasswordGeneratorViewModel by viewModels() override fun onCreate(savedInstanceState: Bundle?) {...
  • u

    user

    07/23/2022, 8:01 AM
    In a Kotlin multi-platform (or JS) project, (how) can one pass custom command line arguments to Node.js? I'm working on a Kotlin multi-platform project, and I need my JS tests to run on Node.js but with custom command line arguments (specifically I need node to run with the --expose-gc flag, because some tests need to trigger garbage collection). Looking at the documentation for the Gradle Kotlin JS DSL I didn't find any mention of how to do that; does anyone know whether it's at all possible and how?
  • u

    user

    07/23/2022, 8:01 AM
    How to sort data on the bases of Priority HIGH,Medium and Low in jetpack compose sealed class Priority{ object High : Priority() object Medium : Priority() object Low : Priority() } I did not be able to sort the data in lazy column on the basis of high,medium and low
  • u

    user

    07/23/2022, 8:41 AM
    Using ReactApplication in Junit4 tests? I'm writing a test for a method that takes a Context as an argument and casts it internally to ReactApplication. I first wanted to handle this with mocks - but if I pass in a mock Context then it can't cast internally to ReactApplication, and I can't pass a mock ReactApplication as it needs to receive a Context as an argument. What is a good method to handle this taking into account that I can't modify the method signature?
  • u

    user

    07/23/2022, 9:01 AM
    How can I change how Ktor encodes spaces in query parameters? By default, Ktor encodes spaces as + in query parameters, which I understand is the general convention. However, the API I have to work with is not particularly well-designed, and so it only accepts %20 as a space, even in query parameters. Is there any way I can tell Ktor to always encode spaces as %20 no matter the context?
  • u

    user

    07/23/2022, 9:01 AM
    Android BLE writeDescriptor return false I have a glucometer device and I want to get recorded data. I wrote and set some descriptors. But one of them returns false for writeDescriptor. There's some code if (characteristic.uuid == GLUCOSE_CHARACTERISTIC) { val charGM = gatt.getService(UUID.fromString("00001808-0000-1000-8000-00805f9b34fb")) .getCharacteristic(GLUCOSE_CHARACTERISTIC)...
  • u

    user

    07/23/2022, 9:01 AM
    Android killed service after 1hour Xamarin I want to write an application that requests data from a socket every 30-60 seconds, and if there is new data, then notifies the user. Wrote a service, but after a while time (50-60 min) Android kills the process. I trying onDestroy() start again but when android kill proccess, it not enter to onDestroy(). What direction to look for? Read about WorkManager, it works with 15 minimum frequency. Thanks in advance [Service] public class DataSource : Service { public override IBinder...
  • u

    user

    07/23/2022, 9:21 AM
    Type mismatch. Required: List<PasswordResponse>! Found: PasswordResponse? Can you help me what I missed? Can you help me what I missed? What is the point I missed here? Can you help me? PasswordGeneratorViewModel : @HiltViewModel class PasswordGeneratorViewModel @Inject constructor(private val repository: PasswordGeneratorRepository): ViewModel() { private val _response = MutableLiveData() val responsePassword: LiveData get() = _response init { getPassword() } private fun getPassword() = viewModelScope.launch { repository.getPasswordGenerate().let...
  • u

    user

    07/23/2022, 9:21 AM
    What is the best way to store Retrofit network call in Room Database I am using MVVM architecture, Room Database and Retrofit. I want to store list of Genres which i fetch from the network and store them in the RoomDB. I want to use LiveData to get list of genres from the database. I understand that this kind of operation should be done within my repository class. I have a slight perspective how to do this, but i am not completely sure how to implement it. Any advice or help is welcome. Thank you in advance
  • u

    user

    07/23/2022, 9:41 AM
    android webview error net::err_too_many_redirects android webview cannot load some urls and gives this error: net::ERR_TOO_MANY_REDIRECTS this answer helps me but I don't want to change cacheMode if possible. is there any other solutions?
  • u

    user

    07/23/2022, 9:41 AM
    Android + Kotlin + Hilt + multi-module app: cannot access application class from a module I'm developing a multi-module app -too have a clear separation of concerns- with Kotlin in which I'm trying to implement Hilt -to also decouple- and I'm having problems accessing application class from modules. First, the structure of my app: app |- Common |- Core |- DTO |- Repository The relation between modules: app > Sees "Common", "DTO" and "Core". |- Common > Sees "DTO". |- Core > Sees "Common". |- DTO |- Repository > Sees "Common" and "DTO". Well, all modules...
  • u

    user

    07/23/2022, 9:41 AM
    RecyclerView hide TextView inside Holder (Custom TV menu) I am creating a menu for my TV app, but since I couldn't get something like a NavigationDrawer working, I am using a RecyclerView with ImageButtons and TextViews. When the RecyclerView loses focus, I want to hide all the TextViews so that the RecyclerView collapses into a smaller menu. As an example you can look at the NetFlix sidemenu. Is there a better way than a RecyclerView? Currently everything is working except for the show/hide of the TextViews. My code:...
  • u

    user

    07/23/2022, 9:41 AM
    How to implement KTX updateLayoutParams() extension How do I add the KTX updateLayoutParams() extension to my project? When I use it, Android Studio says "Unresolved reference: updateLayoutParams"
  • u

    user

    07/23/2022, 10:41 AM
    How to reactively observe the results of a Android Room query that receives arguments I am a beginner in Android. What I want to do is the following Pass parameters received from the screen to the ViewModel and issue a SELECT query by Room. Update the values in the ViewModel. Update the values in the ViewModel Reactively reflect the result of the SELECT in the UI How can I reactively observe a query with arguments? The following ViewModel updateItemsByCategoryId() does not work because the type is different. ViewModel @HiltViewModel class ItemListViewModel @Inject...
  • u

    user

    07/23/2022, 10:41 AM
    Do action when holding a button from bottom navigation bar I wanted to enter a settings page when I hold down the home button on the bottom navigation bar. I looked for how to get the id of a button in the bottom navigation but couldn't find anything. Do you know if I can get a button from this bar? Thanks !
  • u

    user

    07/23/2022, 11:21 AM
    Use updateLayoutParams() on MapFragment I have the following map fragment: mapFragment = supportFragmentManager.findFragmentById(R.id.map_fragment) as SupportMapFragment I can't use updateLayoutParams() on it (mapFragment.updateLayoutParams) because Android Studio says "Unresolved reference: updateLayoutParams" but it works on other types of views. Why? what should i do instead?
  • u

    user

    07/23/2022, 12:01 PM
    How to provide an object using hilt in background thread with coroutine I want provide a realm object in background thread like this: @Module @InstallIn(SingletonComponent::class) object DatabaseModule { @Provides @Singleton fun provideDatabaseScope(): CoroutineScope = GlobalScope + Dispatchers.IO @Provides @Singleton fun provideDatabaseQueue(): ExecutorCoroutineDispatcher = Executors.newSingleThreadExecutor().asCoroutineDispatcher() @Provides @Singleton fun provideGetRealmConfig(accountService: AccountService):...
  • u

    user

    07/23/2022, 12:01 PM
    How to center Dialog into parent Window in compose? I can get parent window size and position on the screen from WindowState and also dialog size and position and based on that get offset needed to be passed for dialog to be in window center. But if dialog has unspecified/dynamic size it doesn't work, same as when window aligned to center it has Alignment.Center instead of Offset.
  • u

    user

    07/23/2022, 1:01 PM
    Bottom Navigation view is not detecting item selected Im trying to make a bottom navigation view to control which fragment is displayed but the navigation view didn't detect any item selected. Here is my Activity Code : val fragmentMore = MoreMenuFragment() val fragmentTransactionHistory = TransactionHistoryFragment() val fragmentLicenseList = DaftarLisensiFragment() replaceFragment(fragmentTransactionHistory) binding.mainNavigationView.setOnItemSelectedListener { when (it.itemId) {...
  • u

    user

    07/23/2022, 1:01 PM
    How to perform operations in case of negative numbers? I wanted to build a calculator app for android and for that I needed a parser to convert string expressions to be solved. Now Java and Kotlin doesn't support eval function and importing a javascript engine just for sake of an operation can open me up to various vulnerabilities. So I made my own calculator parser. Now it's working completely fine, all arithmetic operations are working fine except in negative numbers in crash. I do know what the problem is as I am splitting the string using...
  • u

    user

    07/23/2022, 1:21 PM
    Arrow.kt loading state I used arrow.kt library so many times, I really enjoyed the features they gave to extend kotlin. I like how Either can represent the success/failed states seamlessly. I am just wondering if arrow.kt has a way to represent loading state along with the other two. In other word, we will have a type that offers three states: Success, Failure, Loading. I tried to use Option as right member, but None can't represent loading state as required. Is there any thing I can try?
  • u

    user

    07/23/2022, 1:41 PM
    how to add video to gallery after save with ffmpeg lib? first of all i save video with ffmpeg but saved video in android Q+ not showing in gallery app, so how i can use MediaStore Api to add saved video in gallery, i try this code but its create a null video with duplicate name (1) in gallary : if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { ContentResolver resolver = getContentResolver(); ContentValues contentValues = new ContentValues(); contentValues.put(MediaStore.Video.Media.TITLE, name);...
  • u

    user

    07/23/2022, 1:41 PM
    Kotlin Serialization issues: Class is not registered for polymorphic serialization in the scope of its interface I am facing issues with serialization using Kotlin. I've followed through the steps here https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/serialization-guide.md but unfortunately, no luck... This is my code: sealed interface Convertible { fun convertUserInput(value : String): String } @Serializable @SerialName("CustomConvertible") class...
  • u

    user

    07/23/2022, 2:01 PM
    RxJava Scheduler.Worker equivalent in Kotlin coroutines I try to migrate below code which RxJava to Kotlin coroutines. This uses uses RxJava Scheduler.Worker to do json parsin in own thread. Is there something similar in Kotlin Coroutines? // RxJava class MessagesRepository() { private val messagesSubject = PublishSubject.create() val messages = messagesSubject.toFlowable(BackpressureStrategy.BUFFER) val scheduler = Schedulers.computation() private fun setClientCallbacks() { val worker =...
  • u

    user

    07/23/2022, 2:01 PM
    How to update my composable upon service property update? I'm using a service locator (as advised in https://developer.android.com/training/dependency-injection#di-alternatives, but I'll switch to proper DI later I promise) to handle auth in my app. I have an authentication service that has a user property that I set and unset using logIn and logOut methods I'd like my ContentView to react to changes in auth.user but I can't quite...
  • u

    user

    07/23/2022, 3:01 PM
    How to trigger second flow value? Why second flow is not triggered if value is changed? I log Log.d("AuthorName", "$authorName") and it works. Also when I try to add loadImage() underneath the vm.getImageAuthorFromWikipedia(authorName) it loads image from time to time, so call API works. ViewModel @HiltViewModel class InspirationQuotesViewModel @Inject constructor( application: Application, private val postInspirationQuote: PostInspirationQuote, private val getImageQuotePictureItemUseCase:...
  • u

    user

    07/23/2022, 3:21 PM
    Multiple Repeating Alarm using Alarm Manager I'm working on a small project, which is a pill reminder app. in my Setting Preference i have code like this SettingsPreference.kt ..... override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { setPreferencesFromResource(R.xml.setting_preference, rootKey) ..... notificationPreference?.setOnPreferenceChangeListener { preference, newValue -> alarmReceiver = AlarmReceiver() newValue?.let { when (it as Boolean) {...
  • u

    user

    07/23/2022, 3:21 PM
    Wait for first Flow emit and update second Flow whenever there is a change on first one I implemented an API call and I would like to allow the user to choose the sort order, keeping the choice saved in Datastore Preferences. But I couldn't implement this idea, since both are returning a Flow, I don't know how to make one Flow wait for the other, and whenever the first one emits a new value, update the second. Some example code I'm trying: interface PreferencesRepository { fun getFilter(): Flow } class PreferencesRepositoryImpl @Inject constructor() : PreferencesRepository...
  • u

    user

    07/23/2022, 4:01 PM
    What context should I pass to the AdapterItem from InformationFragment? AdapterItem class AdapterItem(val context: Context, val userList: List): RecyclerView.Adapter() { class ViewHolder(itemView:View):RecyclerView.ViewHolder(itemView){ var numeLista: TextView var caloriiLista: TextView init{ numeLista=itemView.numeLista caloriiLista=itemView.caloriiLista } } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { var itemView = LayoutInflater.from(context).inflate(R.layout.row_items, parent, false) return...
  • u

    user

    07/23/2022, 4:01 PM
    How to add thousands separator for calculator app. KOTLIN I have a calculator app and I want it to show large numbers with spaces between them when users enter their input. Currently, they don't have spaces between them like this: 10000; 100000; 1000000. I want them to show like this: 10 000; 100 000; 1 000 000. The second one looks much neater. Here is my code class CalculatorActivity : AppCompatActivity() { @Suppress("PrivatePropertyName") private var DigitOnScreen = StringBuilder(12) private var operation: Char = ' ' private var leftHandSide:...
Powered by Linen
Title
u

user

07/23/2022, 4:01 PM
How to add thousands separator for calculator app. KOTLIN I have a calculator app and I want it to show large numbers with spaces between them when users enter their input. Currently, they don't have spaces between them like this: 10000; 100000; 1000000. I want them to show like this: 10 000; 100 000; 1 000 000. The second one looks much neater. Here is my code class CalculatorActivity : AppCompatActivity() { @Suppress("PrivatePropertyName") private var DigitOnScreen = StringBuilder(12) private var operation: Char = ' ' private var leftHandSide:...
View count: 7