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

    06/22/2022, 6:51 AM
    Generate Parentheses in Kotlin I wanted to create a program that displays all valid arrangements for n couple of parentheses. The output should be an array sorted in ascending order of ASCII values. The following is the function that needs to be used. fun solution(n: Array): Array { } I tried it using this, but cannot make it fit the above function, fun balancedBracket(result: String, size: Int, open: Int, close: Int): Unit { if...
  • u

    user

    06/22/2022, 6:51 AM
    Get the receiver's number from an SMS on Android I am using the below code to get originatingAddress (the sender's number). import android.provider.Telephony.Sms.Intents.getMessagesFromIntent fun getFullMessage(messageParts: Array): CompleteSmsMessage { messageParts = getFullMessage(getMessagesFromIntent(intent)) messageParts.last().also { part -> return CompleteSmsMessage( originatingAddress = part.originatingAddress, body = messageParts .map { it.messageBody } .reduce { acc, body -> acc + body }...
  • u

    user

    06/22/2022, 7:11 AM
    Add to favourites functionality using MVVM Best Practice I am working with MVVM architecture and trying to use best practices in documentation. Let me explain what I have done and what is my problem. I have a fragment and a parent fragment. When user enters a string to searchview which is in parent fragment, I collect the data and fetch the list to recyclerview. I have a list adapter which takes care of favourite button for each elements in recyclerview. And I implemented a callback to listadapter: val onFavouriteChanged: (id, isFavourited) ->...
  • u

    user

    06/22/2022, 7:11 AM
    Avoid model duplicates in Spring-boot for different dataSources I'm using Spring-Boot with Kotlin and try to save a "Student" object into 2 different databases. (PostgreSQL and Redis) To achieve this I created 2 Student models, because Postgres and Redis need different annotations. @Entity @Table(name = "student") data class StudentPostgres( @Id var id: Int? = null, var name: String? = null, var gender: Gender? = null, var grade: Int? = null ) { enum class Gender { MALE, FEMALE } } @RedisHash("Student") data class...
  • u

    user

    06/22/2022, 8:11 AM
    How can I put the limit for numbers in textfield for android jetpack compose? I have a textfield in android jetpack compose, so I want to put limit for numbers, for example; user can write only numbers from 1 to 10, is it possible to do it in jetpack compose? @Preview(showBackground = true) @Composable fun OutlinedTextFieldComposable() { var text by remember { mutableStateOf("") } OutlinedTextField( value = text, onValueChange = { text = it }, label = { Text("Label") }, keyboardOptions = KeyboardOptions(keyboardType =...
  • u

    user

    06/22/2022, 9:11 AM
    Java cannot access Kotlin's Companion I am trying to use kotlinx serialization in java code. The problem I encounter is that I cannot use Companion object in java code to access it's static serializer() method which is generated by kotlin serializaton plugin. Here is the kotlin code that decalres a serializable class: @kotlinx.serialization.Serializable data class MyData(private val data: String) My mavem pom.xml file is shows below 4.0.0 org.example TestProject 1.0-SNAPSHOT 18 18 1.7.0 1.3.3...
  • u

    user

    06/22/2022, 9:11 AM
    Mocking suspend function so that it rise an exception (Kotlin, unit testing, mockito) I have a suspend function: override suspend fun fetch( userId: String, userChannel: String, deviceId: String, ): List { val docSelector = ... return db.getCollection().find(docSelector).toList() } I want to mock it in the test so that when it is called, an exception is thrown. I did it this way: this is the block of production code which calls the fetch() function and in which I want to jump to line (1) when running from the test...
  • u

    user

    06/22/2022, 9:11 AM
    Kotlin inflate two layouts in one Fragment I have a problem, and I cannot change it, because project is big and I have a task, to get to included layout (B) button in main layout (A). I have a standard binding in onCreaveView, but I need to get to button which is included in layout. My Fragment looks like this now: private val bindingA by viewInflateBinding(FragmentABinding::inflate) private val bindingB by viewInflateBinding(FragmentBBinding::inflate) override fun onCreateView( inflater: LayoutInflater, container:...
  • u

    user

    06/22/2022, 9:31 AM
    "You cannot perform this action on PaymentIntents created by Checkout" on client side Stripe I've started to implement Stripe into my Android app, and that error keeps popping while trying to make payments. I get the paymentIntentID and the clientSecret from the backend, where those are generated. When I pass the clientSecret to the paymentSheet.presentWithPaymentIntent, fill out the card info for the <a href="https://stripe.com/docs/payments/accept-a-payment?platform=android#:~:text=credit%20card%20number-,4242%204242%204242%204242,-with%20any%20expiration" rel="nofollow...
  • u

    user

    06/22/2022, 9:31 AM
    How add kotlin-csv to JetPack Compose project I want to add kotlin-csv to my app but I don't know how to di it. I opened kotlin-csv and I have found that I need to add these lines to build.gradle (Module). I did it implementation 'com.github.doyaaaaaken:kotlin-csv-jvm:1.3.0' implementation 'com.github.doyaaaaaken:kotlin-csv-js:1.3.0' But I can not run my file. I have a error. import com.github.doyaaaaaken.kotlincsv.dsl.csvReader fun main(){ val csvData: String = "a,b,c\nd,e,f" val rows: List = csvReader().readAll(csvData)...
  • u

    user

    06/22/2022, 9:51 AM
    Yelp API Validation Errors(400) - Android Studio I want to do a simple experiment with the yelp api, but I'm stuck at startup and keep getting validation error. I checked and refreshed the API_key and BaseURL etc but the error persisted. MainActivity.kt private const val TAG = "MainActivity" private const val BASE_URL = "https://api.yelp.com/v3/" private const val API_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) {...
  • u

    user

    06/22/2022, 10:11 AM
    Google Map. Android. Fill color outside city area I using goole map in android app. I drawed city area on the map, like this: fun fillCityPolygon(mMap: GoogleMap) { val layer = GeoJsonLayer( mMap, R.raw.city_polygon, this ) val style = layer.defaultPolygonStyle style.strokeColor = R.color.purple style.strokeWidth = 10f style.fillColor layer.addLayerToMap() } I cant understand how i can fill all area outside the city area. Like this: <a...
  • u

    user

    06/22/2022, 10:11 AM
    com.google.android.gms:play-services-ads | ERROR After update it to version 21.0.0, I get an error msg (The Val cannot reassign). implementation 'com.google.android.gms😛lay-services-ads:21.0.0' AndroidView( factory = { AdView(it).apply { adSize = AdSize.FULL_BANNER adUnitId = "ca-app-pub-....62" loadAd(AdRequest.Builder().build()) } }, )
  • u

    user

    06/22/2022, 10:11 AM
    viewmodel init fail in release apk since constructor not found I am using viewmodel in jetpack compose and build a factory like import android.content.Context import android.util.Log import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider internal class MyStateBuilder(val args: Map?, val context: Context) : ViewModelProvider.Factory { override fun create(modelClass: Class): T { try { Log.d("ppx",modelClass.constructors.size.toString()) modelClass.constructors.forEach {...
  • u

    user

    06/22/2022, 10:31 AM
    How to make Navigation Drawer with only two corner with radius Im trying to make a Navigation Drawe with only right corners with radius. My problem is that in the top of the Navigation Drawer, I have a rectangle image and it overlap the radius of the navigation drawer with a custom xml to make this border radius. How can I put this square image in top of the navigation drawer and make it fit with the border radius? Something like this but with corner radius in the navigation drawer. <a href="

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

    " rel="nofollow...
  • u

    user

    06/22/2022, 10:31 AM
    Bitmap.getColor(x, y) crashes on API 28 and below Introduction: I am running my instrumented tests of my SDK on AWS Device Farm, but I see that it crashes when I try to get the pixel color of a Bitmap (bitmap.getColor(x, y)). Problem: I test the color of different view objects, as image views, and I found a way to do it converting the view to a Bitmap and then extracting one certain pixel color. Works well on all my emulators and physical devices. Not in all AWS Device Farm devices with API 28 and below, I have tested it in a API 28 local...
  • u

    user

    06/22/2022, 10:31 AM
    Custom Android CardView Dialog Preview different I want to display a custom dialog using a cardView to display some information. The preview looks exactly like it should and is previewed in Android Studio the following:

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

    The quick_preview.xml xml for this is The dialog uses a custom class...
  • u

    user

    06/22/2022, 10:51 AM
    Stuck in Kotlin Seam Carving Stage 3/6: Look at energy I'm traing to manage the third stage of the Seam Carvinf project on the Kotlin Academy for several days, but I'm stuck. I have no idea why my output is different than the expected one. Could you help me find my mistake? Input

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

    Expected output

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

    My output

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

    The Instruction:...
  • u

    user

    06/22/2022, 10:51 AM
    How do I get an in-depth knowledge of android applications? I make android apps with java and Kotlin and I can get most of the information about almost any app I want to build online. I feel like all I do is read, copy and rewrite code with little tweaks. I don't totally understand what I am doing. I only use already built features and implement, extend or override methods. Is it possible to create an application from scratch without using already built methods or classes? Is it possible for me to handle things myself, like create my own...
  • u

    user

    06/22/2022, 11:11 AM
    How to (de)serialize an instance of a generated data class I need to (de)serialize to and from JSON some of the data classes that are generated by a Gradle plugin. Normally I would just use a library like Moshi or kotlinx.serialization and add the proper annotation to the class I want to serialize but, since this data classes are autogenerated, this is a problem. I would like to avoid manually to map all the fields of the generated data class to some other class that I can (de)serialize, or to write a custom adapter for all these data class so, I was...
  • u

    user

    06/22/2022, 11:51 AM
    Kotlin Paging 3 using Recycler View but List did not showing I used Paging 3 for my Recycler View that had to show some stories in the application. But while I used Paging 3, the lists did not show the item. Before I used Paging 3, the items had been showing including the details. StoriesResponseItem.kt @Entity(tableName = "story") data class StoriesResponseItem( @PrimaryKey @field:SerializedName("id") val id: String, @field:SerializedName("photoUrl") val photoUrl: String, @field:SerializedName("createdAt") val...
  • u

    user

    06/22/2022, 11:51 AM
    IntelliJ IDEA not showing decompiled bytecode I can open a .class file and get a decompiled version of method implementation code, but only for classes compiled from Java source. However, when I open a class file that was compiled from Kotlin source, I get this appearing in the decompiled class window: public final fun test(): Int { /* compiled code */ } How can I get IntelliJ (paid version) to show the compiled code for Kotlin code just as it does for Java-compiled code? Perhaps I can tell it somehow to forget it's been compiled by...
  • u

    user

    06/22/2022, 11:51 AM
    binding breaks after screen rotation I have exception "lateinit property binding has not been initialized" after screen rotation when I try call binding . How I can fix it ? My base fragment code override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?, ): View? { binding = DataBindingUtil.inflate(inflater, contentLayoutID, container, false) return binding.root }
  • u

    user

    06/22/2022, 12:11 PM
    check network state in fragment in android I defined two layers in a fragment, the display of which depends on the internet and gps on and off There is no problem when the program runs, but when I enter another fragment and return to the first fragment, the code does not work properly. onViewCreated override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) //broadcast receiver for check runtime network val registerReceiver = requireActivity().registerReceiver(...
  • u

    user

    06/22/2022, 12:11 PM
    How to publish Android library multiple module on the same repository? When i try to publish my android library with maven-publish plugin and jitpack.io, I must implement link as below, Link: 'com.github.EkremYigit😛ersonal-android-library:1.0.0' But I dont want to add all modules with single link. I want to split links as like below 'com.github.EkremYigit.RepositoryName:myLibrary:1.0.0' 'com.github.EkremYigit.RepositoryName:myLibrary2:1.0.0' How to create "single repo with multiple module library" senario, is there any guideline ? Project structure <a...
  • u

    user

    06/22/2022, 12:11 PM
    Fragment - 'on navigate back' not bahave the same way as back button I'm writing android app, using fragments. There are two main ways to navigate up or back.

    picture of the screenâ–¾

    The first is to use the arrow on the navigation bar (marked with the number 1 in the picture) The second use the system back button (marked with the number 2) I wrote: override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View { ......
  • u

    user

    06/22/2022, 12:51 PM
    How to mock out lambda passed to .use on Closable? Given: suspend fun putS3Object( folderPath: String, emptyContent: ByteStream = ByteStream.fromBytes(ByteArray(0)), ): PutObjectResponse { val request = PutObjectRequest { bucket = bucketName key = folderPath metadata = mutableMapOf() this.body = emptyContent } try { s3ClientFactory().use { s3: S3Client -> return s3.putObject(request).also { logger.info { it } }...
  • u

    user

    06/22/2022, 12:51 PM
    GitHub Packages, Install Android library, Kotlin I successfully uploaded my package to GitHub

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

    In my project when i upload i use def getVersionName = { -> return "1.0.0" // Replace with version Name } def getArtifactId = { -> return "bruno-components" // Replace with library name ID } publishing { publications { bar(MavenPublication) { groupId 'com.bruno.components' // Replace with group ID artifactId...
  • u

    user

    06/22/2022, 12:51 PM
    I am using FusedLocation provider and I don't want my app to crash even if internet services in my phone are off. I have tried using try/catch, no use NOTE: Internet services are OFF intentionally in my phone. Getting error at the below line: addresses = geocoder.getFromLocation(latitude, longitude, 1) I don't want my application to crash even if the internet service is off and want the issue to be caught in catch block. I have implemented the try/catch block, but still my app crashed by giving the below exception: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException is there any solution for my problem. Thanks in advance.
  • u

    user

    06/22/2022, 1:11 PM
    Can't change DatePicker (spinner) buttons color in theme I open DatePickerDialog on click like this, using my theme to enable the spinner mode: val calendar: Calendar = Calendar.getInstance() //show dialog context?.let { DatePickerDialog( it, R.style.customDatePickerStyle, { view, year, month, dayOfMonth -> birthDatePersonalInfoSettingsField.editSettingsField.setText(dayOfMonth.toString() + "/" + (month + 1) + "/" + year) },...
Powered by Linen
Title
u

user

06/22/2022, 1:11 PM
Can't change DatePicker (spinner) buttons color in theme I open DatePickerDialog on click like this, using my theme to enable the spinner mode: val calendar: Calendar = Calendar.getInstance() //show dialog context?.let { DatePickerDialog( it, R.style.customDatePickerStyle, { view, year, month, dayOfMonth -> birthDatePersonalInfoSettingsField.editSettingsField.setText(dayOfMonth.toString() + "/" + (month + 1) + "/" + year) },...
View count: 6