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/23/2022, 4:01 PM
    I am new to Kotlin (New to the world of programmers) and i am not getting what im doing wrong in this code Well hello there! As you know i am new to the world of programmers and i just started learning kotlin and i dont know why am i not getting the result. What i expected --> either "your office is closed" or "you are in office" VS What i got --> 'Process finished with exit code 0' No other result, just this. This is the code: fun main() { val hour = 6 val isWeekend = true var message:String = "nothing" if(isWeekend) { message = if ((hour > 9 && hour < 15)) {...
  • u

    user

    07/23/2022, 4:41 PM
    How to fix two API requests with flow coroutines I have problems to execute two flows with efficient way. Sometimes I have to trigger this method(click on button) twice to have different result it seems that sometimes flow is not triggered well. What could be problem here? My result I would like to achieve. CLick on button -> 1 flow triggered with success result -> (get data from 1 flow) to trigger 2 flow with new data and with success -> update UI usecases class GetImageQuotePictureItemUseCase @Inject constructor(private val api:...
  • u

    user

    07/23/2022, 4:41 PM
    Can't put variables for kts script engine in kotlin I have this code: fun main() { with(ScriptEngineManager().getEngineByExtension("kts")) { put("i", 3) val res2 = eval("i") println(res2) } } which gives me this error: Exception in thread "main" javax.script.ScriptException: error: unresolved reference: i i ^ The evaluation works fine, if I dont try to reference the variable it all works fine. What am I doing wrong to add a variable?
  • u

    user

    07/23/2022, 5:01 PM
    Automatically indent enum parameters table-like in IntelliJ Say I have an enum like this: public enum TestEnum { TEST1(5, 6, 18, 9, 3), TEST2(10, 21, 4, 5, 34), TEST3(4, 5, 8, 2, 16), TEST4(3, 1, 92, 67, 22); TestEnum(int i1, int i2, int i3, int i4, int i5) { } } How can I automatically indent the parameters for the enum to look like this: public enum TestEnum { TEST1 (5, 6, 18, 9, 3), TEST2 (10, 21, 4, 5, 34), TEST3 (4, 5, 8, 2, 16), TEST4 (3,...
  • u

    user

    07/23/2022, 5:21 PM
    Disable ads after in-app product purchase with in-app billing 5 I have set up in-app billing 5 in my application which is mainly about disabling Admob ads after the user makes a purchases , after the user pays for the in-app product , I would like to know what are the possible ways to disable ads after the purchase is made , I have thought about using product flavors but not sure if it is the right approach to follow , on the other hand i'm not using any local or remote database to save the user product purchase details , i'm here seeking an advice from...
  • u

    user

    07/23/2022, 5:41 PM
    How to have multiple custom themes in jetpack compose? My current code is as follows: @Composable fun AppTheme(darkTheme: Boolean = false, content: @Composable() () -> Unit) { val colors = if (darkTheme) DarkThemeColors else LightThemeColors MaterialTheme( colors = colors, typography = MaterialTheme.typography, shapes = MaterialTheme.shapes, ) { content() } } which im calling in main activity like that: @Inject lateinit var application: WeatherApplication override fun...
  • u

    user

    07/23/2022, 5:41 PM
    How to get File object from assets? I have a markdown file in my assets folder. I am using a markdown viewer which takes java.io.File Object as an argument to parse the file on screen. But i don't know how to get a File Object from a file in assets folder. Is there a way i can achieve this. I tried URI way but it failed. This is my code snippet which may help val markDown = File("file:///asset/GalacticAstronomy.md") if (markDown.exists()) { Toast.makeText(baseContext, "File exist",...
  • u

    user

    07/23/2022, 6:01 PM
    How do I allow only one specific fragment to have both portrait and landscape orientations in Android? In my Android application, I have added android:screenOrientation="portrait" to all activities in my Android.manifest and android:orientation="vertical" to every activity's/fragment's respective layout so that the app can only be viewed in portrait mode. However, there is one fragment in particular that I want to enable both portrait and landscape orientations. This fragment extends the DialogFragment() class as it's a full-screen fragment. This fragment is contained within another fragment,...
  • u

    user

    07/23/2022, 6:21 PM
    Replace baseContext in Fragment I have a little problem with baseContext in Fragment, in a nutshell, I'm making an application with Retrofit and RecyclerView, and for practice I decided to make them in Fragment, and then I ran into a problem that I don't know how to replace baseContext in override fun onResponse, I just replaced it with context and it still doesn't work import androidx.lifecycle.ViewModelProvider import android.os.Bundle import androidx.fragment.app.Fragment import android.view.LayoutInflater import...
  • u

    user

    07/23/2022, 6:21 PM
    What is wrong with my code. I am unable to draw on the screen I have checked my code several times and don't know where is it going wrong. i am trying to build a drawing app and after doing all this code I am unable to get any output. Not able to draw on the canvas. please help me get rid of this issue. This is my DrawingView.kt package com.example.drawingapp import android.annotation.SuppressLint import android.content.Context import android.graphics.* import android.util.AttributeSet import android.view.MotionEvent import android.view.View import...
  • u

    user

    07/23/2022, 6:21 PM
    onClick() in LazyColumn I am trying to set onClick() in IconButton like this IconButton(onClick = { navController?.navigate(NavigationScreen.Search.route) }) { Icon( painter = painterResource(id = R.drawable.hamburger_setting), "UserTweetSetting", modifier = Modifier .size(12.dp) .align(Alignment.CenterVertically),...
  • u

    user

    07/23/2022, 7:21 PM
    kotlin coroutines trying to build recipes app based on recipessdb with kotlin +coroutines and mvvm but i have an error that i don't know here is my api sevice interface GetDataServices { @GET("categories.php") suspend fun getCategoryList(): Category here is my Repositor class Repository( var getDataService : GetDataServices ?=null, var dao: RecipeDao?=null, var application: Application ){ //-1-get Main category from api suspend fun getMainCategory(): Category? { var res_rep= getDataService?.getCategoryList() return res_rep Log.v("res_rep_get",res_rep.toString())...
  • u

    user

    07/23/2022, 7:41 PM
    Android Studio Cannot Install Any SDK (Im Beginner) Im starting Android Programming so Im installing Android Studio. When Im trying to run the wizard, I get an error: "Missing SDK"

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

    I didn't download any SDK and I know that Android Studio can download and install SDK's itself. Then, I click on Next to see what's happening:

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

    I know this page should has a Todo list to download SDK's and it will...
  • u

    user

    07/23/2022, 8:01 PM
    Saving radio group checkedId with SharedPreferences to make the radio button selection to be the same when resuming Kotlin I'm trying to program an android app with android studio that counts steps taken by the user. I'm trying to make a settings/options activity where the user can both set their height and preferred measure unit. I was able to code the height selection so that it is saved into SharedPreferences so that every time the user returns to the settings activity the height stays the same. I'm trying to do the same to the measure unit selection but it doesn't seem to work. I've put the measure unit...
  • u

    user

    07/23/2022, 8:41 PM
    What is the type of a Kotlin 'data class'? I have a situation where I need to create a copy of data class object. I don't know in advance which of the many data classes I have will come in into the function. I do know, however, that only data classes will be used as input to this function. This is what didn't work: fun doSomething(obj: Any): Any { obj.copy(...) //
  • u

    user

    07/23/2022, 10:21 PM
    Hoping to display a value every 3 seconds using thread.sleep. However, it's not working im taking this kotlin basics in google and im in the "intro to debugging" section.. total noob here and i've managed to plow through the subjects and now im stuck here.. so the expected outcome is for the textview to display a quotient every three seconds but when i run the app, it shows a static value of 60. private val TAG = "MainActivity" MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) Log.d (TAG, "this...
  • u

    user

    07/23/2022, 10:41 PM
    Incompatibility between TornadoFX and lowagie iText I have a desktop application developed with TornadoFX (jaxaFx + kotlin) and when I insert the lowagie iText library in the dependencies declaration, the application stops working. When I compile with the iText library, the application just doesn't run. It doesn't return any error messages and doesn't even enter Main. Has anyone had a similar problem? dependencies { implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.72") implementation("org.jetbrains.kotlin:kotlin-reflect:1.3.72")...
  • u

    user

    07/23/2022, 11:01 PM
    Compose - Hoverable &amp; clickable line I'm trying to make a composable with a line shape. These lines will be connecting any two coordinates together, meaning it won't be a straight horizontal/vertical line, I know I can use divider for that. I can do a line in drawWithCache (compose desktop's equivalent of Canvas), but these lines are neither hoverable nor clickable. Afaik clipping a box with a custom shape won't be helping here because hover and click events will still work with a rectangle shape. Is there any way at all that I...
  • u

    user

    07/24/2022, 12:01 AM
    Getting incoming call phone number in KOTLIN Hi im looking for a way to detect incoming calls in KOTLIN. Ive successfully implemented firebase but im stuck here. Telephony manager seems have been deprecated so i have no idea on how to achieve my goals Thanks to anyone will answer
  • u

    user

    07/24/2022, 12:21 AM
    Problem with displaying admob ads inside vpn app I'm having trouble showing admob ads inside my vpn app When users from countries with low eCPM connect to VPNs from countries with higher eCPM, Google does not know the real country of the user and therefore limits the sending of ads. For example, it shows ads that are for the UK to people in Japan and vice versa There is no way that admob remembers the user's country during the initial implementation? or any other solution
  • u

    user

    07/24/2022, 2:01 AM
    How to allow memory grwoth in tensorflow 1.15 for Java? I'm using kotlindl, which runs on tensorflow java 1.15. I expected my code to run on an RTX GPU, but I ran into an error described in this Tensorflow issue. The solution to this issue, it...
  • u

    user

    07/24/2022, 2:21 AM
    Kotlin-Java Script Warnings coming for basic project I am trying to execute a basic Kotlin JS project but getting warnings. pls help how to fix the warnings. Compiled with problems:X WARNING asset size limit: The following asset(s) exceed the recommended size limit (244 KiB). This can impact web performance. Assets: WordCountWeb4.js (254 KiB) WARNING entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (244 KiB). This can impact web performance. Entrypoints: main (254 KiB)...
  • u

    user

    07/24/2022, 2:41 AM
    how to lock device for fixed time with kotlin or flutter hey I wanna develop app that lock the device for a while it's like this app bellow https://play.google.com/store/apps/details?id=forinnovation.phoneaddiction&hl=EN I can lock screen one time, but users can unlock easily app needs to be foreground always does anyone know how to realize that?? It's just for android (if available for iphone, please let me know) and using...
  • u

    user

    07/24/2022, 4:41 AM
    No noarg super constructor for CLASS CLASS Kotlin 1.5.0 I have a error when trying to build my android app after bumping the kotlin version to 1.5.0. I am thinking its related to haveing a parcelized class and using the no-arg plugin. I have the following class import android.os.Parcelable import kotlinx.parcelize.Parcelize sealed class CDSAppbarProfile( val count: Int ) : Parcelable { @Parcelize class User( val origincount: Int, val imageUrl: String ) : Parcelable, CDSAppbarProfile(origincount)...
  • u

    user

    07/24/2022, 5:01 AM
    What are the UI blocking thread operation in Java or Kotlin Is there a documentation list of all UI blocking operation in Java or Kotlin like InputStream.read()? Or other way to identify blocking operation without needing to run the project?
  • u

    user

    07/24/2022, 5:21 AM
    Kotlin list extension function I have an extension function shown below infix fun List.sumList(that: List) = this.zip(that, Int::plus) I am now trying to make this extension function generic so that it works on list of integers as well as float and double. listOf(1,2,3).sumList(listOf(10,20,30)) gives me [11, 22, 33] Below is my attempt of writing the same extension function using generics inline infix fun List.sumListNew(that: T): List = when { T is Double -> this.zip(that, Double::plus) else ->...
  • u

    user

    07/24/2022, 6:01 AM
    How to implement zoom feature for RecyclerView? I need to implement a RecyclerView using GridLayoutManager to represent seats of a stadium. On item (seat) selection, some information pops up and finally the user can book it. The problem is, high number of seats per row on a small screen make it difficult for the user to select an item. So, I want to implement a zoom feature where user can zoom in a part of the RecyclerView to make it easier to click on an item. How's id done?
  • u

    user

    07/24/2022, 6:21 AM
    Kotlin Program Not Running I have the following kotlin code fun main() { println("How many mines do you want on the field?") val mines = readln().toInt() val minefield = Minefield(mines)... However, once I enter a number, it doesn't do anything. When I attempted to debug it, I saw that it took mines in, but kept expecting something. There's no other readln() in the initializer, and the Minefield class signature is class Minefield(mines: Int) What's going wrong?
  • u

    user

    07/24/2022, 7:21 AM
    How to cancel CountdownTImer in Android kotlin? I want to cancel the timer when user presses the back button or minimizes the app. I have tried using cancel() on 'override fun onDestroy()' but still the timer is running. Below is my countdown timer code countDownTimer = object : CountDownTimer(Constants.timerDuration, 1000) { override fun onTick(millisecondFinished: Long) { binding?.tvTimer?.text = (millisecondFinished / 1000).toString() Log.i("millis", "onTick: $millisecondFinished") }...
  • u

    user

    07/24/2022, 7:21 AM
    kotlin testing error cannot create parent directories When I run test, I am getting the error when I try to test if Datastore.edit had been called: java.io.IOException: Unable to create parent directories of /data/user/0/com.example.app.test/files/datastore/user.preferences_pb It is a small class that handles Datastore, which is the following: Pref.kt class Pref { companion object { @Volatile private var INSTANCE: Pref? = null private var dataStore: DataStore? = null fun getInstance(context: Context):...
Powered by Linen
Title
u

user

07/24/2022, 7:21 AM
kotlin testing error cannot create parent directories When I run test, I am getting the error when I try to test if Datastore.edit had been called: java.io.IOException: Unable to create parent directories of /data/user/0/com.example.app.test/files/datastore/user.preferences_pb It is a small class that handles Datastore, which is the following: Pref.kt class Pref { companion object { @Volatile private var INSTANCE: Pref? = null private var dataStore: DataStore? = null fun getInstance(context: Context):...
View count: 4