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

    06/20/2022, 12:41 PM
    Try to remove unused string but it's not working I'm trying to remove the unused string from string.xml but it's showing noting in the preview I have many strings which are unused I follow the step open string.xml right-click select reflector -> unused resource
  • u

    user

    06/20/2022, 12:41 PM
    Kotlin: most efficient coroutine based http client What would you suggest as the most efficient coroutine based http client for kotlin. One additional requirement is to be also able to limit the number of in progress requests.
  • u

    user

    06/20/2022, 1:01 PM
    Kotlin Data Type Syntax What does the following data type means: () -> String It is being used in the following context. fun sampleFun(message: ()-> String)
  • u

    user

    06/20/2022, 1:01 PM
    How to restrict enums in Kotlin? I have an enum with many values; error codes for example, or some official list of coded values. In my application, I have several functions where only a subset of those values is admissible. How can I derive restricted enums that contain only a subset of the original enum? For example, I have an externally provided dictionary of error codes that model as enum: enum class APIError(val: errorCode: Int) { INCORRECT_CHARACTER(1), MISSING_VALUE(2), TOO_SMALL(3), TOO_LARGE(4) } In one...
  • u

    user

    06/20/2022, 1:41 PM
    Widget in sub menu. When text is selected How can I add my app to sub menu when I selected text in phone and if I click android open widget. Google translator have something like that. When I selected text sub menu opens and I choose translator, android open Google translator widget.

    select from sub menu▾

    widget▾

  • u

    user

    06/20/2022, 2:01 PM
    TextView not displaying full text in BottomSheetDialog My text is not being shown correctly despite having maxLines="10"

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

    Here is my xml code for the TextView Tried to implement scrolling programmatically but nothing happens uAbout.movementMethod = ScrollingMovementMethod()
  • u

    user

    06/20/2022, 2:01 PM
    No Bean Definition Found exception 2022-06-20 18:59:22.201 20149-20149/com.xx.xxxx E/AndroidRuntime: FATAL EXCEPTION: main Process: com.xx.xxxx, PID: 20149 java.lang.RuntimeException: java.lang.reflect.InvocationTargetException at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:681) Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791) at...
  • u

    user

    06/20/2022, 2:01 PM
    How can I limit barcode scanner to once? I try to code a barcode scanner with Jetpack Compose and Google ML Kit. I use ImageAnalysis with the STRATEGY_KEEP_ONLY_LATEST and call a class BarCodeAnalyzer who initialize and create the barcodeScanner. But when I scan a barcode, my code detect two time the same barcode and open two screens. So how can I pause scan ? Or stop the imageAnalysis when I found a barcode ? AndroidView AndroidView( factory = { context -> val previewView = PreviewView(context) val preview =...
  • u

    user

    06/20/2022, 2:01 PM
    Avoid erasing generics in Runtime with Generics in Kotlin I have a "repository" that encapsulates some datastore, my goal is to get values from there by using generics. However I keep getting : Cannot use 'T' as reified type parameter. Use a class instead. interface IRepo { fun retrieve(key: String): T? } class MyRepo: IRepo { private var sharedPrefs override fun retrieve(key: String): T? { return getByType(key) --> here T causes : Cannot use 'T' as reified type parameter. Use a class instead. } private inline fun...
  • u

    user

    06/20/2022, 2:21 PM
    How to open the cash drawer in android device I'm using kotlin in my android application I have connect the cash drawer with the printer , I want the code that its open the cash drawer with the printing please help me
  • u

    user

    06/20/2022, 2:21 PM
    How we can compare textfield values are same value in jetpack compose? I have register screen in android jetpack compose, and I have ScreenA and ScreenB, in ScreenA I have email and in ScreenB I have again mail and confirm mail, so I want to control those three email values is same value. In ScreenA when I put any mail, in ScreenB both mail must be same mail with ScreenA, any solution? ScreenA: @Composable fun ScreenA( navController: NavController, model: MyViewModel ) { val email = remember { mutableStateOf(TextFieldValue()) } Column(...
  • u

    user

    06/20/2022, 2:41 PM
    Issue With App Engine and Spring Boot : Request is missing required authentication credential. Expected OAuth 2 access token, I'm developping an App Engine application, that is basically an API. So it's a backend Application I started this project approximatively one year ago, and i had no issue deploying it on App Engine. But since yesterday, each time i want to deploy a new version (with little to no change between the last working version uploaded 2 months ago) i always got the same error on my logs : { "textPayload": "java.io.IOException: Server returned HTTP response code: 500 for URL:...
  • u

    user

    06/20/2022, 3:01 PM
    How to declare external typescript types in kotlin I need to access a Typescript library (react-admin) from kotlin-js In particular this types definitions https://github.com/marmelab/react-admin/blob/master/packages/ra-core/src/types.ts How do I declare in kotlinjs for example the following types ? export type AuthProvider = { login: (params: any) => Promise; logout: (params: any) => Promise; checkAuth:...
  • u

    user

    06/20/2022, 6:31 PM
    How can I replace rectangles with images/assets using Jetpack Compose [Kotlin]? I am currently developing a Sokoban game in Kotlin for an Android app and at this point I have an algorithm that generates a matrix of strings where each string refers to a specific game element, e.g., "#" - Wall, "0" - Floor, "@" - Player, "$" - Box, etc... Based on that matrix, I am using Jetpack Compose to draw in a canvas rectangles with different colors so I can distinguish the elements (wall, floor, ...) of the Sokoban game. At the moment, this is the result: <a...
  • u

    user

    06/20/2022, 6:31 PM
    Check if a list of objects contains the object without the filter call to get true/false result I got listOf and I have Pojo object. I need to check if the list has objects with the same values and return true or false without filtering. Trying val result = myPojo in pojoList Got this error None of the following functions can be called with the arguments supplied. CharSequence.contains(Char, Boolean = ...) defined in kotlin.text CharSequence.contains(CharSequence, Boolean = ...) defined in kotlin.text CharSequence.contains(Regex) defined in kotlin.text
  • u

    user

    06/20/2022, 6:31 PM
    Validating JSON schema with intersections and unions classes in Kotlin I'm thinking about rewriting small web server project that I have from TypeScript to Kotlin. The problem that I have is server accepts a JSON with unions and intersections. For the purpose of this example: I want incoming JSON to have a string field with either the name one or name two, but not both or none of them, e.g. {"one": "some text"} or {"two": "some other text"} I want format of incoming request be dependent on one of its fields, e.g.: { "someFlag": false, // or can be missing...
  • u

    user

    06/20/2022, 6:31 PM
    Rxjava emit only if a condition is met I have a polling function that is mapped to 3 different states private fun pollFromApi(): Observable { return Observable.interval(3L, TimeUnit.SECONDS, schedulerProvider.io()) .startWith(0L) .flatMap { api.getCall().toObservable() } .map { when { condition1 -> State1 // convert response to State1 condition2 -> State2 // convert response to State2 condition3 -> State3 // convert response...
  • u

    user

    06/20/2022, 6:31 PM
    error: [Dagger/DependencyCycle] Found a dependency cycle with Dagger2 I am trying to use @BindsInstance in a Component Builder, but can't inject dependency into a module That is the component: @Component(modules = [MainModule::class]) interface MainComponent { fun inject(activity: MainActivity) @Component.Builder interface Builder { @BindsInstance fun mainDep(dep: MainTest): Builder fun build(): MainComponent } } That is the module: @Module class MainModule { @Provides fun provideMainTest(mainTest: MainTest) =...
  • u

    user

    06/20/2022, 6:31 PM
    Date format of milliseconds shows SSS only I'm trying to get the current time including milliseconds, but it only shows SSS. Here is my code: import android.text.format.DateFormat import java.util.Calendar ... String.format( "%s IOException: %s", DateFormat.format("HH🇲🇲ss.SSS", Calendar.getInstance().time), ex.message ) It outputs 20:41:03.SSS some other text. Also tried just toasting the date, same output.
  • u

    user

    06/20/2022, 6:31 PM
    How can we combine 2 array lists in java [duplicate] import java.util.* fun main(args: Array) { val firstArray = arrayOf(-1, 2, 3) val secondArray = arrayOf(1,2,-3,4) println(Arrays.toString(firstArray)) println(Arrays.toString(secondArray)) val iArray = firstArray.intersect(secondArray.toList()).toIntArray() println(Arrays.toString(iArray)) } the above program returned [2] how can we achieve like [-1,2,3],[1,2,-3,4] would return [[-1,1],[2,2],[3,-3]]
  • u

    user

    06/20/2022, 6:31 PM
    Fragment displaying a grey field I am still a bit new to fragments in android studio but I was wondering if this is usually how fragments are displayed as on the phone. It appear as a grey background above my activity, as shown in this image: https://gyazo.com/9d5569718c5092debfeaab1c631b0046 This is my MainAppActivity code: class MainAppActivity : AppCompatActivity() { private lateinit var appBarConfiguration: AppBarConfiguration...
  • u

    user

    06/20/2022, 6:31 PM
    Map is not opening I wanted to remove title bars in all of my activities and changed .DarkActionBar to .NoActionBar in themes.xml, which resulted in crash when i click a button to open a map, then i changed android:theme in each activity except for map to NoActionBar, which didnt help, now i go back in files history for back up, use an old one and map still crashes when opened. I tried syncing project with gradle files and invalidating cache - 0 result. Here's some code that was changed:...
  • u

    user

    06/20/2022, 6:31 PM
    Dynamic Url with @Post request retrofit + hilt I am trying with Hilt and Retrofit2 to create a Post request with a dynamic URL. I am getting the error @Url cannot be used with @POST URL (parameter #1) I need the query to be dynamic too @POST("{id}") suspend fun getConfiguration( @Url url: String, @Body configRequest: ConfigRequest, @Query("id") id: String ): Config the builder @ExperimentalSerializationApi @Provides @Singleton fun provideApi(@ApplicationContext context: Context): Api{ val contentType =...
  • u

    user

    06/20/2022, 6:31 PM
    Why is my android app just crashing when I run it? Why is my app just crashing? It is supposed to be a training app that gives you instructions via multiple pages. But it is throwing this error in the console when i run it on my phone and on my virtual phone. These are the files that are in my project. Please help. E/AndroidRuntime: FATAL EXCEPTION: main Process: com.hectorwithc.training_handbook, PID: 7400 java.lang.RuntimeException: Unable to instantiate activity...
  • u

    user

    06/20/2022, 6:31 PM
    Service Loader Can't Find Provider I am having trouble getting the service loader to find my providers. My set up is as follows: I have 4 modules: EntryPoint Library Version1 Version2 In Library, I have an interface defined: interface Parent{ fun doSomething() fun getName() } In Version1 and Version2, I override that interface with a class called Impl. I also place META-INF/services/parent.package.path.Parent in the resources folder, with child.package.path.Impl as its contents. In EntryPoint I have a main...
  • u

    user

    06/20/2022, 6:31 PM
    Kotlin Validation issue with Register function in login system When on the Login page and when pressing register, it takes you to register, but when clicking on register button on register page, it adds user to database regardless if info is provided or not and then takes you back to login page. I want the validation to happen before the execution. Currently it does validate, but executes regardless. Please advise. class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) {...
  • u

    user

    06/20/2022, 6:31 PM
    Why calling a private constructor in Kotlin results in error as "Cannot access &lt;init&gt;"? What is &lt;init&gt;? If you use factory method in Kotlin to create an object, like: class Person private constructor(val firstName:String , val lastName: String) { companion object { fun createPerson(firstName: String, lastName: String): Person { return Person(firstName, lastName) } } } Calling factory method works: val person1 = Person.createPerson("Niels", "Abel") And also, of course, you can't call the constructor directly: val person2 = Person("Évariste", "Galois") The...
  • u

    user

    06/20/2022, 6:51 PM
    Android Studio cannot find R (Resources) after Java to Kotlin conversion Problem Every time I paste a Java code from somewhere, I select yest to the Android Studio prompt asking to convert it from Java to Kotlin. But after that happens, I seem to have all my previously working R based resources like R.drawable and R.string as unresolved.

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

    What have I tried so far ? Every time this happens, I copy the converted code and then Ctrl+Z up to a point where everything is back to being resolved...
  • u

    user

    06/20/2022, 7:11 PM
    Ktor Client: parent property in Resources with nested classes In ktor client 2.0.2 docs, on Resources with neseted classes section, it is stated: Nested classes should have a property with an outer class type. From an example Here @Serializable @Resource("/users") data class Users {...
  • u

    user

    06/20/2022, 7:51 PM
    How to change data using platform chanel? I have profile data in the form of a Map. I need to pass them to the platform and return them back with a modified update date using the platform channel. How can I change the update date and revert back? The data should be updated on clicking the ElevatedButton. My Flutter Page: class HomePage extends StatefulWidget { const HomePage({Key? key}) : super(key: key); @override State createState() => _HomePageState(); } class _HomePageState extends State { static const platform =...
Powered by Linen
Title
u

user

06/20/2022, 7:51 PM
How to change data using platform chanel? I have profile data in the form of a Map. I need to pass them to the platform and return them back with a modified update date using the platform channel. How can I change the update date and revert back? The data should be updated on clicking the ElevatedButton. My Flutter Page: class HomePage extends StatefulWidget { const HomePage({Key? key}) : super(key: key); @override State createState() => _HomePageState(); } class _HomePageState extends State { static const platform =...
View count: 4