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/12/2022, 1:51 PM
    Buttons will not show on displayed fragment I am currently creating a chat application for a project in Android Studio using Kotlin, Firebase Cloud Storage and Cloud Firestore, and Glide, and I am following a few tutorials to do so. Everything was fine until I created a fragment to handle the user's account settings, such as name, bio, etc. The fragment appears to work and the edit text fields and profile picture can all be edited and interacted with, but neither of the buttons for saving and signing out seem to be displayed, and I...
  • u

    user

    07/12/2022, 2:11 PM
    How to Inject constructor to abstract class with Dagger2 I have an abstract ViewModel abstract class AbstractViewModel( protected val dataStore: dataStore, protected val schedulerProvider: SchedulerProvider ): ViewModel() { abstract fun doSomething() } that is inherited by many ViewModels class InheritedViewModel1 @Inject constructor( dataStore: DataStore, schedulerProvider: SchedulerProvider ) : AbstractViewModel(packageDataStore, schedulerProvider) { override fun doSomething() {} } class InheritedViewModel2 @Inject...
  • u

    user

    07/12/2022, 2:11 PM
    Why am I getting a java.lang.ClassCastException in Kotlin? I wrote this sample code that I extracted from a library that I'm making because it is causing a java.lang.ClassCastException and I don't understand why. Here's the code: interface Event data class Update(val message: Message?) open class Message(open val text: String?) data class TextMessage(override val text: String) : Message(text = text) class MessageReceiveEvent( val message: Message, ) : Event class TextMessageReceiveEvent( val message: TextMessage, ) : Event fun...
  • u

    user

    07/12/2022, 2:11 PM
    app crashed when i click on ImageView placeholder i just write a code to get permissions to READ_EXTERNAL_STORAGE when i click on an ImageView. All of things going fine but i run the app and clicked on ImageView then the app got crashed. here is my code: in OnCreate: var iv_user_image:ImageView = findViewById(R.id.iv_user_image) iv_user_image.setOnClickListener(this@UserProfileActivity) my methods: override fun onClick(view: View?) { if (view != null){ when (view.id){...
  • u

    user

    07/12/2022, 2:31 PM
    Kotlin Plugin Error on Eclipse (Version: 2022-03) I have installed Kotlin plugin on my Eclipse IDE. But when I try to open a Kotlin file, the editor shows the below error. java.lang.NoClassDefFoundError: Could not initialize class org.jetbrains.kotlin.idea.j2k.J2KPostProcessingRegistrarImpl at org.jetbrains.kotlin.core.model.KotlinCommonEnvironmentKt.createKotlinCoreApplicationEnvironment(KotlinCommonEnvironment.kt:257) at...
  • u

    user

    07/12/2022, 2:51 PM
    if else return in kotlin

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

    Error : Kotlin: Type mismatch: inferred type is String but Unit was expected code : fun main() { val a = 2 var data: String = if (a != 2) { return "Hello" } else { return "World" } }
  • u

    user

    07/12/2022, 3:11 PM
    Jetpack Compose – BottomBar is under Bottom Navigation I've implemented BottomBar via Scaffold in Jetpack Compose. It works fine with a smartphone with gesture navigation. But when legacy bottom buttons are enabled, the overlap my BottomBar.

    screenshot▾

    My code: Scaffold( bottomBar = { BottomMenu() } ) { innerPadding -> Surface( color = AppTheme.colors.background.primary, modifier = Modifier...
  • u

    user

    07/12/2022, 3:51 PM
    android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running? in react-native android I want to show a custom view when the app is turned off or when the app is turned on, depending on the phone state. so I use WindowManager. but get error message W/System.err: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running? W/System.err: at android.view.ViewRootImpl.setView(ViewRootImpl.java:1596) W/System.err: at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:509) W/System.err: at...
  • u

    user

    07/12/2022, 3:51 PM
    NoBeanDefFoundException but scope is already defined I'm trying to solve this issue: I'm receiving a crash whenever i try to click on a push notification in certain fragment, that would redirect me to another fragment in the app. I defined my module like this: scope(named()) { factory { (view: DetailContract.View) -> DetailPresenter( view = view, monitoring = get(), api = get(), storage = get(), imageProvider = get()...
  • u

    user

    07/12/2022, 4:11 PM
    Passing a click action for preview in android jetpack compose What I have : I have a compose class that has a button I want to see the preview in the design view Issue I am facing : For the click How to pass as an object on the line I have marked in code Is this possible ? OnBoardingActionButton.kt @OptIn(ExperimentalPagerApi::class) @Composable fun OnBoardingActionButton( modifier : Modifier, pagerState: PagerState, onClick : () -> Unit ){ OnBoardingActionButtonContent(pagerState,onClick) } @OptIn(ExperimentalPagerApi::class)...
  • u

    user

    07/12/2022, 4:11 PM
    String var returning "Kotlin.Unit" instead of text in Kotlin finally I was able to capture the error in the response of an http request but now I am trying to return the result in a String and the only thing I get is a "Kotlin.Unit", why does it return that instead of text?? private suspend fun createUserPrepare():String?{ var result:String?="" try { val retrofit=retrofit.getInstance() val payload=registerPayload() val requestBody =...
  • u

    user

    07/12/2022, 4:31 PM
    How can I prevent the endIcon from getting focus when the Next key is pressed in TextInputLayout? I don't want the end Icon of EditText to get focus when the next key is pressed. I have given the imeOptions as 'actionNext' . Now when I click the Next key , if the edittext is empty , it moves to the next edittext placing the cursor there. But if the edittext is not empty, clicking the next key shifts the focus to the endIcon. Is there a way I can prevent this ?
  • u

    user

    07/12/2022, 4:31 PM
    My program only returns the days of a non-leap year Kotlin fun main(args: Array) { val year = 2020 var leap = false val month = 10 if (year % 4 == 0) { if (year % 100 == 0) { leap = year % 400 == 0 } else leap = true val numDay = when (month){ 1 ->"31" 2 ->"29" 3 ->"31" 4 ->"30" 5 ->"31" 6 ->"30" 7 ->"31" 8 ->"31" 9 ->"30" 10 ->"31" 11 ->"30" 12 ->"31" else ->"Invalid Argument" } I can't read the numDay of a leap...
  • u

    user

    07/12/2022, 5:31 PM
    How can I create regex for bank transactions Asking if anyone is able to help me get the regex for bank transactions for Android kotlin
  • u

    user

    07/12/2022, 5:31 PM
    cancelling a suspend function in kotlin if the same function is called again I want to cancel the function i created which simply increments a counter value. For example, if the specific function is triggered by click, I only want to display the log for the last uninterrupted click within 2 seconds. Basically, i want the function to cancel itself if called again if its ongoing (delay is ongoing). Is there such thing in kotlin? val counter = mutableStateOf(0) suspend fun addCounter(){ counter.value++ delay(2000) Log.e("click cat","click $counter") }`
  • u

    user

    07/12/2022, 6:11 PM
    Check if TextfieldValue is accepting space as characters I am using OutlineTextField and the value is taken from TextFieldValue. I have a save button on top of it which gets enabled if there is entered text and disabled vice versa. I have validated using below code

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

    val textFieldState = remember { mutableStateOf(TextFieldValue(EMPTY)) } onSaveClickEnabled = textFieldState.value.text.isNotEmpty(), But the above code is not validating if space entered initially. It enables...
  • u

    user

    07/12/2022, 6:31 PM
    Spring Data JPA filtering by best match I want to implement filtering for multiple fields of an entity which is ordered by best match. By best match I mean that the more of the filtered fields match the higher in the order the result is listed. I want this to work dynamically, so I can add more filters later on. I have been looking for a solution for a long time now and I didn't find an elegant way to do this with JPA. My approach is to concatenate all my predicates with or and then order them by how many of the fields match. This...
  • u

    user

    07/12/2022, 7:11 PM
    The custom token format is incorrect. Please check the documentation I'm trying to re-authorize a user after changing the password. But I am getting this error The custom token format is incorrect. Please check the documentation What could be wrong? I do every step in order: Change the password first I update the token I use a token for re-authorization still getting this error. Sometimes I get an error, something like You need to log in to change your password but I'm already logged in. Then I logout and login, and try to change the password again, but I...
  • u

    user

    07/12/2022, 8:11 PM
    Cannot access nested type through typealias I have a Quantity/Units library in Kotlin which has classes like Weight, Distance, Force. These classes inherit from a Quantity class and each contain a nested class Unit with information about the respective units for each type of quantity. As a kind of physical oddity, the consumption of an electric car (e.g. kWh/100km) is technically the same dimension as a force, so the Force.Unit class contains both NEWTON and KILOWATTHOUR_PER_100_KILOMETERS. Of course, we use FuelConsumption for...
  • u

    user

    07/12/2022, 8:11 PM
    USB Serial Kotlin I am looking for an Android USB-Serial example in Kotlin. Almost every example I have found is in Java, which I suppose is still ok, but I haven't been able to compile any of them successfully. I am quite new to Android / Kotlin, and just want to get the most basic send and receive going from my phone to a USB device over an OTG cable. Any help / pointers / suggestions gratefully received. Thank you Garrett
  • u

    user

    07/12/2022, 8:31 PM
    @Autowired not working inside testcontainers I am using test containers to make integration tests with the MSSQLServer image and when I am trying to inject my repository I am recieving the following error: lateinit property modelRepository has not been initialized And this confuse me because I'm using the same path I used to create the test but using a postgress database in another project. My test archive: package *.models.integration import *.portadapter.repository.ModelRepository import *.builders.ModelBuilder import...
  • u

    user

    07/12/2022, 8:51 PM
    kotlin-reflect-1.6.10.pom:2:1: Content is not allowed in prolog VS code As I am new in Flutter Dart ,When I am trying to build demo flutter app in my Android Phone in Android Studio OR VS code I keep getting this error, FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:compileDebugKotlin'.
    Could not resolve all files for configuration ':app:kotlinCompilerClasspath'.
    > Could not resolve org.jetbrains.kotlin:kotlin-script-runtime:1.6.10. Required by: project :app >...
  • u

    user

    07/12/2022, 9:11 PM
    How to parse this date/time in Java/Kotlin? I have this NMEA timestamp: 120722202122 and I want to parse it. I tried import java.time.LocalDateTime import java.time.format.DateTimeFormatter fun main() { println(LocalDateTime.parse("120722202122", DateTimeFormatter.ofPattern("DDMMyyHHmmss"))) } Playground but I get an Exception: Conflict found: Field MonthOfYear 1 differs from MonthOfYear 7 derived from 2022-01-12 I don't know what the Exception wants to tell...
  • u

    user

    07/12/2022, 9:31 PM
    Understanding Haskell realToFrac function I meed to migrate some Haskell code to Kotlin and I have some confusion trying yo understand the next code: floor ((realToFrac minutes :: Double) / 60) minutes is a integer value, my Kotlin code, looks like this: floor((minutes / 60).toDouble()) But I am not getting the expected results. I think I am missing the realToFrac part. I do not have Haskell experience. If it possible could you give me some idea of this line of code in another language such Java or JavaScript.
  • u

    user

    07/12/2022, 9:31 PM
    Kotlin Mockito veirfy not invoked in a coroutine test I got an error while doing a kotlin coroutine test. I'm pretty sure the function is called because I saw the logs. I'm not sure what does the error message mean. Is this related to coroutine (running on different thread) or the context (using a customized context to trigger onStart)? Wanted but not invoked: testActivity.fetch(); -> at com.example.cws.testActivity.fetch(testActivity.kt:322) However, there was exactly 1 interaction with this mock:...
  • u

    user

    07/12/2022, 9:31 PM
    ComposeUI: More convenient way to create this layout with lines connecting several composables What do I want to achieve? I want to create the following layout. It is important that the vertical "connecting" lines go inside the numbered boxes:

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

    What did I already try (first, naive approach)? I created the layout using a composable and a few lines. The numbered boxes get a boolean parameter which indicate if the top or bottom lines inside the box are shown. There also are vertical lines between the composables...
  • u

    user

    07/12/2022, 9:51 PM
    Running Sum of 1d Array in kotlin Hey guys I am learning data structure. I am trying to solve a problem of leetcode. Given an array nums. We define a running sum of an array as runningSum[i] = sum(nums[0]…nums[i]). Return the running sum of nums. Example 1: Input: nums = [1,2,3,4] Output: [1,3,6,10] Explanation: Running sum is obtained as follows: [1, 1+2, 1+2+3, 1+2+3+4]. I tried my solution and it working fine and I understand all stuff. My solution class Solution { fun runningSum(nums: IntArray): IntArray {...
  • u

    user

    07/12/2022, 9:51 PM
    How could the text written in editText modify the progressbar in Kotlin in Android Studio? I'm trying to make the progressbar interactive with the editText. When the number written in EditText is greater than 10 the progressbar increases by 10%. The code I wrote doesn't work of course but I don't see how to do it: class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.first_gamble) val progressbar = findViewById(R.id.progressBar) val converter =...
  • u

    user

    07/12/2022, 10:11 PM
    How to execute shell command in Kotlin and get return value from shell [Android] I am able to execute shell commands (that has a return value) in Kotlin [Android] using the following lines of code: fun getFrequencyLevelsCPU0(): Unit { val process: java.lang.Process = java.lang.Runtime.getRuntime().exec("su -c cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies") process.waitFor() } The above lines of code are capable of running the shell command but the output of the command should be something as follows if the command was...
  • u

    user

    07/12/2022, 10:31 PM
    Can someone explain AES/CBC/PKCS5Padding encryption? Hello all who reading this! I am starting to take a dive into Encryption. Now i have found this sort of application for the encryptions of Strings and objects. now I was curious how it worked and what causes what . Is there someone who can explain the following code, like step for step? import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; import java.nio.charset.StandardCharsets; import java.security.InvalidAlgorithmParameterException;...
Powered by Linen
Title
u

user

07/12/2022, 10:31 PM
Can someone explain AES/CBC/PKCS5Padding encryption? Hello all who reading this! I am starting to take a dive into Encryption. Now i have found this sort of application for the encryptions of Strings and objects. now I was curious how it worked and what causes what . Is there someone who can explain the following code, like step for step? import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; import java.nio.charset.StandardCharsets; import java.security.InvalidAlgorithmParameterException;...
View count: 6