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/21/2022, 9:21 PM
    Cannot use list in lazycolumn in kotlin I am using LazyColumn in project. When I am passing the list it giving me error. Can someone guide me what is the error? ResultScreen.kt @Composable fun ResultScreen(nearestResultList: List?) { LazyColumn( Modifier .fillMaxSize() .background(getBackgroundColor()) ) {...
  • u

    user

    07/21/2022, 9:41 PM
    Kotlin - What is the easiest way to create a generic data object to transform into JSON for API requests? It is very easy to create native generic objects that can be serialized into JSON in dynamically typed languages like Python, PHP, or JS. With Kotlin, it seems like I will need to define a serializable data class, at the very least, in order to be able to compose JSON for transmission. This is workable, but it breaks down pretty quickly when the data is complex or variable, and because of this is not very reusable. Is there a good approach (using Kotlin) that allows for similar behavior to...
  • u

    user

    07/21/2022, 9:41 PM
    Backhandler not working in jetpack compose Hey I am using BackHandler from this stackoverflow. When I am pressing back button it's not working. Can someone guide me on this. ResultScreen.kt @Composable fun ResultScreen(navController: NavHostController, nearestResultList: List?) { SportsResultTheme {...
  • u

    user

    07/21/2022, 10:41 PM
    How to implement Banner Ad in RecyclerView Kotlin? The app closes when i try to start the activity where the banner ad is, and i receive the error "lateinit property mAdView has not been initialized" This is my Adapter class ComoSeJuegaAdapter (private val context: Context, private val dataset: List): RecyclerView.Adapter(){ class ComoSeJuegaViewHolder(val view: View): RecyclerView.ViewHolder(view) { val textView: TextView = view.findViewById(R.id.item_title_como_se_juega) val imageView: ImageView =...
  • u

    user

    07/21/2022, 11:01 PM
    Console input is interupted by output I have a Kotlin console application with a lot of log messages. For testing, I want to enter certain admin commands in the console. However, each log message apparently erases my console input buffer. How can I reliably read a line or even just individual chars from the console, while other threads are printing log messages to that console? fun main() { thread(isDaemon=false, name = "ConsoleThread") { while(true) { println("(doit) do something")...
  • u

    user

    07/22/2022, 12:01 AM
    Convert this java array to a kotlin equivalent array 2d Hi I'm trying to convert this java array to a kotlin array: String[][] data = {{"May","22"}, {"June","45"}}; I tried two ways but my tableView is not showing any record. This is my way number 1: val mayo: Array = arrayOf("Mayo", "20") val junio: Array = arrayOf("Junio", "40") val data2d1 = arrayOf(mayo, junio) The I pased this array to the adapter of this library: <a href="https://github.com/ISchwarz23/SortableTableView" rel="nofollow...
  • u

    user

    07/22/2022, 2:01 AM
    Write a kotlin program that prints the number that is repeated the most in a consecutive way I'm kind of stuck, I don't know how to make the second loop to start 1 position above the first loop in Kotlin. I have an array (named myArray) with 10 elements, I need to Write a Kotlin program that prints the number that has the most consecutive repeated number in the array and also prints the number of times it appears in the sequence. The program must parse the array from left to right so that if two numbers meet the condition, the one that appears first from left to right will be...
  • u

    user

    07/22/2022, 2:01 AM
    Can't find constructors of Kotlin class class Foo(context: Context) { ... } class Bar(context: Context): Foo(context) { ... } When I try to construct a Bar like: Bar::class.java.getConstructor(Context::class.java).newInstance(context) I get NoSuchMethodError. If I look at Bar::class.java.constructors the result is empty. What am I missing?
  • u

    user

    07/22/2022, 2:41 AM
    How to use the new ComponentActivity with ViewBinding and the other old AppCompatActivity components According to this question, I tried to update my deprecated menus codes like setHasOptionsMenu , onCreateOptionsMenu and onOptionsItemSelected in my fragments and all app, but I should replace AppCompatActivity to ComponentActivity(R.layout.activity_example) but after doing this I see there's some problem, first I confused about how to use ViewBinding with it when I should remove setContentView(binding.root) from activity second the...
  • u

    user

    07/22/2022, 4:41 AM
    Hilt java.lang.IllegalStateException: Unsupported metadata version. Check that your Kotlin version is &gt;= 1.0 I'm facing issue while adding hilt dependencies in my project plugins plugins { id 'com.android.application' id 'org.jetbrains.kotlin.android' id 'kotlin-kapt' id 'realm-android' id 'androidx.navigation.safeargs.kotlin' id 'kotlin-parcelize' } dependencies //Dependency injection with Hilt implementation("com.google.dagger:hilt-android:2.38.1") kapt("com.google.dagger:hilt-android-compiler:2.38.1") implementation 'androidx.core:core-ktx:1.8.0' implementation...
  • u

    user

    07/22/2022, 4:41 AM
    Why onBackPressed() is not fired when touching Back-Button / Android In order to reproduce my issue I made a tiny project. It has two activities. Here is the MainActivity.kt file: package me.soft.trybackbtnaction import android.content.Intent import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.view.View class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) } fun...
  • u

    user

    07/22/2022, 4:41 AM
    Ktor | How to connect FreeMaker-Template with a CSS-File? I just started learing Kotlin and Ktor for Web Development. I started creating a Template and everything worked perfectly but now I want to add style to my Templates. In the Kotlin Docs they add style with HTML but I would like to add style with a CSS-File. Is that possible? NK
  • u

    user

    07/22/2022, 5:21 AM
    convert biginteger to bit I am stuck with an exercise at JetBrain Academy, with BigInteger(Kotlin). I should write a code snippet to convert a (BigInteger) number of exbibyte into bits: if the input is 1 as BigInteger, it displays 9223372036854775808. In the hints it says I should use pow(63).(Exbibyte = 2^63 = 9 223 372 036 854 775 808‬ Bit) My problem is if I use pow(), I can use only double as the biggest range. But with double I cannot display a BigInteger number.
  • u

    user

    07/22/2022, 5:41 AM
    Checking if finger is over certain view not working in Android I am working on a paint app with the following layout:

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

    For the paint app, I detect touch events on the Canvas using onTouchEvent. I have one problem, I want to also detect touch events in which the user begins the swipe on the root and then hovers over the Canvas. To achieve this, I added the following code: binding.root.setOnTouchListener { _, motionEvent -> val hitRect = Rect()...
  • u

    user

    07/22/2022, 5:41 AM
    What is the best way to play an alarm ringtone when broadcast reciever is called? I am having trouble finding the best way to activate an alarm tone. My broadcast receiver is called, the media player starts, but then stops. after about a second when my alarm app is closed and not open in recent apps. It will play continuously if the alarm app is open. Does anyone know the best way to play a sound once a alarm broadcast receiver goes off? what I am currently using in the broadcast receiver. val mediaPlayer1 = MediaPlayer.create(context2, R.raw.geese)...
  • u

    user

    07/22/2022, 6:21 AM
    How to add kotlinc to macOS PATH ENVIRONMENT from my Android Studio JetBrains Toolbox App plugin? I want to use kotlinc to compile Kotlin file to JVM ByteClass and got a response: zsh: command not found: kotlinc I know I can install it using homebrew. But, I already have Android Studio installed using JetBrains Toolbox App and I want to avoid having two copies of Kotlin. Anybody know how to add my Kotlin plugin into my PATH ENVIRONMENT? so I can use kotlinc in my terminal. I'm using macOS. Thank you for your help
  • u

    user

    07/22/2022, 6:41 AM
    Convert Comparable&lt;*&gt; but get error inferred type is Any? but Nothing was expected I am trying to convert this piece of java code to kotlin public int compare1(Comparable c, Object o) { return c.compareTo(o); } to kotlin code: fun compare1(c: Comparable, o: Any?): Int { return c.compareTo(o) } But get error Type mismatch: inferred type is Any? but Nothing was expected Any reason why this error occurs? Thanks
  • u

    user

    07/22/2022, 7:21 AM
    Unit testing Androoid Mockk argument capture interface SomeAPIHandler { fun getUserContent(apiInterface: APIInterface) } interface APIInterface { fun onSuccess(responseModel: T) fun onError(errorModel: ErrorModel) } In my presenter class, it is called like: apiClient.getUserContent(object : APIInterface { override fun onSuccess(responseModel: UserModel) = handleSuccess(responseModel) override fun onError(errorModel: ErrorModel) = handleGetUserModelError() }) I am getting code coverage issue from...
  • u

    user

    07/22/2022, 7:41 AM
    How to check whether my app following S.O.L.I.D. Principle I have created one app in kotlin, I tried to follow all OOPS and SOLID principles in my app. But after development of whole app i want to check whether any class is missing or breaking rules of SOLID principle. Try 1 Review the whole code in each class whether they are following SOLID principles of not. But if i have large number of files then it will take more time. How can we do it automatically to check whether my app is following SOLID principles.
  • u

    user

    07/22/2022, 8:21 AM
    Android Studio Kotlin how to send layout to a fragment? I am new about fragment stuffs.I have MainActivity in my app module and it has a fragment.And also I have features->List module and inside that module I have list layout and other layouts(cardviews) which will display on list layout as recyclerview.Once I haven't any fragment stuff.I was displaying my recyclerview on my MainActivity.Now I want to have a fragment in my Main Activity and content of the list.xml will be in the activitymain.xml and when MainActivity initiliaze it should...
  • u

    user

    07/22/2022, 8:41 AM
    How can I find the color color created with bitmask? how can I find the color color created with bitmask? For example, what is the color equivalent of this expression? color = -16777216
  • u

    user

    07/22/2022, 9:01 AM
    Kotlin compiler reports unused expression in constructor for builder taking vararg lambdas We have a relatively simple builder pattern we use for test data generator in Kotlin. The builders follow the pattern: class ThingBuilder private constructor( var param1: Int = 1, var param2: Boolean = true ) { private constructor(vararg inits: ThingBuilder.(ThingBuilder) -> Unit) : this() { inits.forEach { it(this) } } fun build(): Thing { return Thing( param1, param2 ) } companion object { fun...
  • u

    user

    07/22/2022, 9:01 AM
    Quastion aboud FloatingActionButton (diamond) I trying to make FAB with diamond shape.

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

    A lot of articles is saying the same:

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

    Ok, let's go to my code: And the result is:

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

    Whats wrong with this FAB ? Why it is circle instead of diamond shape ? It should be diamond, like examples in all articles all over...
  • u

    user

    07/22/2022, 9:01 AM
    Response header has duplicated values I have two simple microservices through which the download file flows, but for some unknown reason some header values are duplicated. First service where is Response build: @POST @Path(PRINT_PREVIEW) fun print(@Valid printRequest: PrintRequest): Response { // printPreview is Pair val printPreview = printService.printPreview(printRequest) return Response.ok(printPreview.second) .header("Content-Disposition", "attachment; filename=${printPreview.first}")...
  • u

    user

    07/22/2022, 9:21 AM
    How to change the value of state object without using _? In my app I perform a request to an API that should return a boolean. Inside the ViewModel class I have these 2 objects: private val _isAvailableState = mutableStateOf(Success(false)) val isAvailableState: State = _isAvailableState One is mutable and the other one isn't. Here is how I read the value: fun checkAvailability() = viewModelScope.launch { repository.checkAvailability().collect { response -> _isAvailableState.value = response } } Is there any way in which I can...
  • u

    user

    07/22/2022, 9:41 AM
    How to run Channel first tflite model in Android I am able to run my custom tflite model in android but the output is totally wrong. I suspect it is due to my model needs input shape [1, 3, 640, 640] but the code makes channel last ByteBuffer. I have created tensor buffer like this TensorBuffer.createFixedSize(intArrayOf(1, 3, 640, 640), DataType.FLOAT32) but I still suspect inside the for loop, the channel is not properly set in the flat input (ByteBuffer). I have copied this code from example where the required model shape was [1,32,32,3]...
  • u

    user

    07/22/2022, 10:01 AM
    Should you use Delegates.observerable() or SharedFlows for custom events? I'm working with ble devices on Android and want to implement custom events. I have the functionalities I need already in C# with Xamarin, so I'm just translating the code most of the time. In C#, I would use delegate and event for custom events, Kotlin offers the Delegates.observerable() functionality. I tested it with the following code and it looks like it works suspiciously flawlessly: var peripheralFound: MyBlePeripheral by Delegates.observable(MyBlePeripheralImpl()){ _, _,...
  • u

    user

    07/22/2022, 10:41 AM
    Converting java to kotlin -- streams I am learning Kotlin, and not know it properly. I have a piece of code in Java: private static Signature[] createSignatures(String... encodedSignatures) { return Arrays.stream(encodedSignatures) .map(encodedSignature -> new Signature(Base64.decode(encodedSignature, Base64.DEFAULT))) .toArray(Signature[]::new); } I want to convert it to Kotlin, and I have reached till here: private static Signature[] createSignatures(String... encodedSignatures) { return...
  • u

    user

    07/22/2022, 10:41 AM
    compile error: Supertypes of the following classes cannot be resolved I have a gradle project with proto3 generator: buildscript { repositories { mavenCentral() } dependencies { classpath("com.google.protobuf😛rotobuf-gradle-plugin:0.8.14") } } ... dependencies { ... implementation("com.google.protobuf😛rotobuf-java:$protoBufCoreVersion") } protobuf { protoc { artifact = "com.google.protobuf😛rotoc:$protoBufCoreVersion" } } Also, I have config for adding generated source code to classpath:...
  • u

    user

    07/22/2022, 11:01 AM
    Kotlinx Serialization, inlining sealed class/interface With a structure similar to the following: @Serializable sealed class Parameters @Serializable data class StringContainer(val value: String): Parameters() @Serializable data class IntContainer(val value: Int): Parameters() @Serializable data class MapContainer(val value: Map): Parameters() // more such as list, bool and other fairly (in the context) straight forward types And the following container class: @Serializable data class PluginConfiguration( // other value val parameters:...
Powered by Linen
Title
u

user

07/22/2022, 11:01 AM
Kotlinx Serialization, inlining sealed class/interface With a structure similar to the following: @Serializable sealed class Parameters @Serializable data class StringContainer(val value: String): Parameters() @Serializable data class IntContainer(val value: Int): Parameters() @Serializable data class MapContainer(val value: Map): Parameters() // more such as list, bool and other fairly (in the context) straight forward types And the following container class: @Serializable data class PluginConfiguration( // other value val parameters:...
View count: 3