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/12/2022, 6:11 AM
    Convert UTC date string like "2022-07-07T08:17:12.117000" to your local Timezone in Kotlin and Java. Alternative to Moment library available in react I have used the moment library to convert the date string in my local timezone in react but i have to implement the same in android but the problem is moment library is not available for java/kotlin. I have tried every possible solution on stactoverflow but the exception occur while parsing the date string. Format of the string is: 2022-07-07T08:17:12.117000 and want the output: Jul-07-2022 01:47 pm
  • u

    user

    07/12/2022, 6:51 AM
    how to compare only by date (without time) in jooq? I have column with type timestamp with time zone. The table contains the following value "2022-06-30 22:56:29.183764 +00:00". I want to do a date-only search. how to compare only by date (without time) in jooq? I've tried this, but it doesn't work. .where(MY_TABLE.UPDATED_AT.cast(LocalDate::class.java).eq(cashDate))
  • u

    user

    07/12/2022, 7:11 AM
    implementing hilt in android with kapt Execution failed for task ':app:kaptDebugKotlin' I have been using hilt in my several android projects. But since I have updated my android studio to latest version Chipmunk// 2021.2.1, this error comes every time when I just build project Execution failed for task ':app:kaptDebugKotlin'. A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction java.lang.reflect.InvocationTargetException (no error message) I am checking it on sample app which is just just one dependency...
  • u

    user

    07/12/2022, 7:31 AM
    Jooq newRecord from map doesn't map camelCase to snake_case I want to populate Record from Patch request that has stored values in map. However Jooq doesn't map camelCase keys in map to snake_case. Is there any possibility how to change that globally? Data class example: class PlantProtectionPatchRequest(val changes: Map = mapOf()) { val decisionHolder: String? by changes val isEko: Boolean? by changes } When i use dsl.newRecord(TABLE,plantProtection.changes) doesn't work, but dsl.newRecord(TABLE,plantProtection) would be mapped correctly....
  • u

    user

    07/12/2022, 7:51 AM
    How to set annotations on a method using reflection? I'm trying to unit test an aspect. val joinPoint = mock() val methodSignature = mock() val roleArray = arrayOf("someTestRole") val annotation = AccessCheck::class.constructors.first().call(roleArray) val method = this.javaClass.getMethod("myMethod") method.setAccessible(true) a) method.annotations = roleArray b) method.annotations[0] = annotation Cannot invoke b) because method.annotations returns null. Cannot invoke a) because method.annotations is val. Cannot...
  • u

    user

    07/12/2022, 8:31 AM
    How to keep running a Health application in background (wear OS / Kotlin) I know that there is similar topic here: How to keep running an application in background in Android Wear(Galaxy watch 4) using Kotlin but I have quite different problem. Here is two type of receiving Health data from sensors: <a href="https://github.com/android/health-samples/tree/main/health-services" rel="nofollow...
  • u

    user

    07/12/2022, 8:31 AM
    List find method finds nothing, but let is called (?!) i have the following code: myList { it.code == item.bin }.let { // 1 } ?: run { // 2 } I would expect that, if item is found, I enter block 1 , otherwise block 2 ; But instead I enter block 1 in all cases, and if nothing is found , it is null Android studio seems aware of this, as the block 2 is grey (it is code never called), but I can't figure why Please may someone explain why ?
  • u

    user

    07/12/2022, 9:11 AM
    A problem occurred evaluating project ':app'. (flutter) im trying to clone project, im fixing the android embedding problem, etc. and im facing this problem. `FAILURE: Build failed with an exception. Where: Build file 'C:\Users\muham\OneDrive\Documents\KP\sipintar-enterprise-mobile-dev_upgrade\sipintar-enterprise-mobile-dev_upgrade\sipintar-enterprise-mobile-dev_upgrade\android\app\build.gradle' line: 25 What went wrong: A problem occurred evaluating project ':app'. org/gradle/api/services/BuildService Try: Run with --stacktrace option to get...
  • u

    user

    07/12/2022, 9:11 AM
    How to pass/recevice data from java/Kotlin to C++ code or vice versa in android I am working on AOSP11/12(Android) and want to communicate data from java/Kotlin to C++ code or vice versa. Is that better way to create new service and communicate data or Need to create NDK application ? Can you please suggest your valuable suggestions. Thanks in advance.
  • u

    user

    07/12/2022, 9:11 AM
    How can I inject an application shared ViewModel throught Hilt I need to share a view model with most activities in my app At first, I tried this way @HiltViewModel class SharedViewModel @Inject constructor() : ViewModel(){ ... } @AndroidEntryPoint class ActivityA : BaseActivity(){ private val sharedViewModel: SharedViewModel by viewModels() } @AndroidEntryPoint class ActivityB : BaseActivity(){ private val sharedViewModel: SharedViewModel by viewModels() } It was built successfully, but Hilt actually created a new instance for each...
  • u

    user

    07/12/2022, 9:31 AM
    How get IMEI of device? I a beginner in android development and I try to get device IMEI but I have a problem of permission. I don't have android.permission.READ_PRIVILEGED_PHONE_STATE property in my project but the function getImei() of TelephonyManger.java require this permission. How can I resolve this? I am a little lost.
  • u

    user

    07/12/2022, 9:51 AM
    Payload in Jwt token is going as simple text instated of application/json I am generating a signed JWT token. I am able to create a token but the payload is not setting as a application/json format inside setClaims() I am using this library implementation 'io.jsonwebtoken:jjwt:0.7.0' This is my code to generate a token fun getJWT(userInput: JsonObject) : String { val s = "secretKey" val encodedBody : String = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { Base64.getEncoder().encodeToString(s.toByteArray()) }else {...
  • u

    user

    07/12/2022, 9:51 AM
    Navigating in a navigation drawer with composables I am trying to set the navigation so that you can with the drawer menu navigate between composables when pressing the icons/text in the drawer. But when I click the icons/texts nothing happens, no navigation to the respective screens are achieved! I have created screens for the respective one. How can I make a successful navigation ? This is my set-up so far: MainDrawer layout: @Composable fun MainDrawer() { val scaffoldState = rememberScaffoldState() val scope =...
  • u

    user

    07/12/2022, 9:51 AM
    Kotlin: Split Sequence&lt;T&gt; by N items into Sequence&lt;Sequence&lt;T&gt;&gt;? How to "take(N)" iteratively - get a Sequence, each inner sequences having next N elements? I am writing a high-load application in Kotlin. I have tens of thousands of entries to insert to a database. I want to batch them by, say, 1000. So I created a loop: val itemsSeq = itemsList.iterator().asSequence() while (true) { log.debug("Taking $BATCH_SIZE from $itemsSeq") val batchSeq = itemsSeq.take(BATCH_SIZE) val squareBatch = applySomething(batchSeq, something)...
  • u

    user

    07/12/2022, 10:11 AM
    SQLite INSERT, changes() sometimes return 1, even if row already existed I've got dedup table: CREATE TABLE UniqueFile (filePath TEXT NOT NULL UNIQUE, created INTEGER NOT NULL DEFAULT (strftime('%s', 'now'))) which along with SQLite changes() function I use to determine if file entry is inserted for the first time or not. Below function is supposed to indicate if the entry is processed for the first time: fun insertFilePath(filePath : String) : Boolean { val db = this.writableDatabase db.execSQL("INSERT OR IGNORE INTO UniqueFile (filePath)...
  • u

    user

    07/12/2022, 10:31 AM
    searchview with recyclerview android I want to write a search in my program that has a suggestion. This should be done with a get request, just like you see in the picture, and a token should also be used. Does anyone know how to do this? Or suggest a sample code?

    enter image description hereâ–¾

  • u

    user

    07/12/2022, 10:31 AM
    java.lang.AssertionError: Verification failed: call 1 of 2: Router(mockRouter#172).xyz()) was not called I am getting weird issue when running on my unit test. I have this function internal fun getPendingStatusAction( status: XYZ ): (() -> Unit)? { var action: (() -> Unit)? = null this.yo = yo if (isAwaitingIdVerification(status)) { action = { router.xyz() } } else if (status == XYZ.PURCHASE) { action = { router.xyz() } } return action } When I run single unit test it complete fine, but when I run whole file unit...
  • u

    user

    07/12/2022, 10:31 AM
    How I should get name of the property from json response? I have some JSON response, which I'd like to display to the user. It has about 170 properties. I'd like to make a hashmap, which will store String, that should store property name, and double, which should store property value "object":{ "firstName" = 1.1111 "SecondName" = 2.2222 etc... } So it should looks like this: key = "first name" and the value = 1.1111 Since I've got it via retrofit, I've prepared a model class which already has declared all of the variables needed to get proper...
  • u

    user

    07/12/2022, 11:11 AM
    Room TypeConverter with constructor error: java.lang.IllegalArgumentException I have been struggling with this error for a long time. I have seen similar topics while no answer has brought the result. Following this tutorial https://www.section.io/engineering-education/storing-custom-data-types-with-custom-typeconverter-in-room-database/. Error: java.lang.RuntimeException: Unable to start activity...
  • u

    user

    07/12/2022, 11:11 AM
    how do i get an Array from a different class in Kotlin how to i access my Arraylist from another class i am trying to add two variables to a single position. var nc = findViewById(R.id.noteContent) as String var nt = findViewById(R.id.noteTitle) as String if (!nc.isEmpty() || !nt.isEmpty()) { get(noteArray(.add(nc,nt) i am new to kotlin and i don't know java. i think i need to use a getter but i am not sure how do it my arraylist "noteArray always come up as unresolved reference it's in my main class with the code....
  • u

    user

    07/12/2022, 11:11 AM
    mutableStateListOf change not reflecting in UI - Jetpack Compose in my ViewModel: private val _itemList = mutableStateListOf() val itemList: List = _itemList fun likePost(newPost: Post){ val index = _itemList.indexOf(newPost) _itemList[index] = _itemList[index].copy(isLiked = true) } Here my Post data class: data class Post( val id: Int, val name: String, val isLiked: Boolean = false, ) And here my Composable: val postList = viewModel.itemList LazyRow(content = { items(postList.size) { i -> val postItem =...
  • u

    user

    07/12/2022, 11:31 AM
    How do I solve Overload resolution ambiguity. All these functions match Please, I'm new to kotlin how do I solve this? ivProfileUserImage!!.setOnClickListener { if(ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED){ //showImageChooser() }else{ ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE), READ_STORAGE_PERMISSION_CODE) } }
  • u

    user

    07/12/2022, 11:31 AM
    IntelliJ theme plugin fails to build (fatal error trying to buildSearchableOptions) As a maintainer of the theme plugin Cute Pink Light Theme for IntelliJ, I want to build releases for updated IntelliJ versions without getting any compilation errors or run-time errors. Currently I get either a fatal build time error, or, using a workaround to skip building searchableOptions, a non-critical run-time error every time an IDE starts using the theme, although my plugin is...
  • u

    user

    07/12/2022, 11:51 AM
    Optimal way to do Cross region Intergration test Which one do we prefer! Either Single test with multiple group support. Data provider providing data @DataProvider(name = "theDataProvider") fun theDataProvider(): Array = arrayOf( if (realmValue.equals(US, true)) input["inputForSuccessUS"].toString() // It could be realm or check the current group being executed from context. Also switch instead of if else else input["inputForSuccessEU"].toString() ) @Test(groups = [EU, US], dataProvider = "theDataProvider") fun `theTest`(input:...
  • u

    user

    07/12/2022, 11:51 AM
    onClick button listeners in CardLayout not working I have two buttons in my CardLayout that I want toast to show: When button clicked, show "Saved" When button clicked, copied to clipboard I have the text in place, it should work, however there are no error codes so difficult to understand. My CardLayout is in recycler view, is that why it isn't showing? CardLayout.xml CardLayout.kt package com.example.what2do_v6.ui import android.content.ClipData import...
  • u

    user

    07/12/2022, 12:11 PM
    How to convert MutableLiveData into HashMap? I have a MutableLiveData which hold retrofit response. Is there a way to get data from inside, and "break" it into something like key, and value? Here's the log of the MutableLiveData Object(a=1, b=2, c=3, d=4 ....) How I can get data from it, so I can convert it into HashMap with String, and Int parameter?
  • u

    user

    07/12/2022, 12:11 PM
    How to capture a video with CameraX without saving the output to the Gallery? I am following the official documentation to capture a video with CameraX, and I want to avoid saving the captured video in the gallery. For now I am working on this part of the documentation code: // Create MediaStoreOutputOptions for our recorder val name = "CameraX-recording-" + SimpleDateFormat(FILENAME_FORMAT, Locale.US) .format(System.currentTimeMillis()) +...
  • u

    user

    07/12/2022, 1:11 PM
    Android Compose in an exsiting project is very slow at first time I Added compose to an existing project. I rewrited a fragment ui with compose , and when I'm starting the fragment it takes a long time to start. Adding a fragment from another fragment: val fragment = FragmentWithComposeUi() requireActivity().addFragment(fragment, R.id.fragment_container, "FragmentWithComposeUi") addFragment() function to add the fragment. fun FragmentActivity.addFragment(fragment: Fragment, container: Int, tag:String) { val currentFragment =...
  • u

    user

    07/12/2022, 1:31 PM
    Multiple ads for a single reward on android I currently have an android app that can load and display one rewarded ad that gives the use a specific reward, using AdMob. I want to make the user watch 2 ads sequentially (without exiting the ad activity) in order to get that reward, meaning watch two ads in a row in order to get a single reward. I didn't find anything in the documentation that could help me on how to implement this, can anyone share useful resources/tips on that?
  • u

    user

    07/12/2022, 1:51 PM
    user input in kotlin

    https://i.stack.imgur.com/fQYt3.pngâ–¾

    I want to get user input in the variables a, b, c. how can I do that thing ??? code : fun main() { val a = 10 val b = 5 val c = 12 if (a > b && a > c) { println("a is greater") } else if (b > c) { println("b is greater") } else { println("c is greater") } }
Powered by Linen
Title
u

user

07/12/2022, 1:51 PM
user input in kotlin

https://i.stack.imgur.com/fQYt3.pngâ–¾

I want to get user input in the variables a, b, c. how can I do that thing ??? code : fun main() { val a = 10 val b = 5 val c = 12 if (a > b && a > c) { println("a is greater") } else if (b > c) { println("b is greater") } else { println("c is greater") } }
View count: 2