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/08/2022, 12:31 PM
    Navigation to local HTML Android Studio The idea is to make the link (in this photo) navigate to a local HTML:

    Photoâ–¾

    So when you click on Privacy Policy, it opens the local HTML. This message is stored in an strings.xml code like this: Check our Privacy Policy (./hosp_eula.html) And in the layout i reference to it like this: But it doesn't work due to the fact that i don't know how to make reference to the HTML file...
  • u

    user

    07/08/2022, 1:11 PM
    Android Kotlin Fragments: ''Attempt to invoke virtual method on a null object reference'' My code in MainActivity: val buttonbckbrowse = findViewById(R.id.buttonbck) buttonbckbrowse.setOnClickListener { val webView = findViewById(R.id.webViewBrowse) webView.goBack() Toast.makeText(baseContext, "Back", Toast.LENGTH_SHORT).show() } buttonbck is in a different fragment. When trying to run my app I get ''Exception: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object...
  • u

    user

    07/08/2022, 2:11 PM
    How can i navigate to different fragments from my MainActivity action bar menu icon? I want to have control over the menu item navigation to different fragments from the main activity. Here's the main activity class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) val binding = DataBindingUtil.setContentView(this, R.layout.activity_main) Timber.plant(Timber.DebugTree()) val navController = this.findNavController(R.id.myNavHostFragment)...
  • u

    user

    07/08/2022, 2:31 PM
    Android Studio adds closing curly brace although a closing brace is already present Since today I experience a really annoying behaviour in Android Studio. It happened after a restart to clear the cache. I have the following situation:

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

    After pressing enter the following happens:

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

    Instead of just adding a new line Android Studio adds two new lines and a closing curly brace. This happens for all scenarios where the pointer is...
  • u

    user

    07/08/2022, 2:31 PM
    How to set text in recyclerviev to the center with animation? I have recyclerview with expandable element. When it expands I would like to have the text in the center horizontally, I tried setGravity, but it is in ConstraintLayout and maybe because of it it doesn't work. Additionally, is it possible to add during this process any fancy animation?
  • u

    user

    07/08/2022, 2:51 PM
    Jetpack Compose runtime does not recompose on pointer input, possibly due to threading (Huge code warning) I'm working on a Jetpack Compose integration library. The application side provides render functions and input handlers, which in place are all running on the main thread and shouldn't be blocked. As for integration, I first set up a UI context as follows: object UIContext { private var scheduledStop: Boolean = false private var hasFrameWaiters: Boolean = false private val clock: BroadcastFrameClock = BroadcastFrameClock { hasFrameWaiters = true } private val...
  • u

    user

    07/08/2022, 2:51 PM
    How to save Webview state when switching between different fragments using Tablayout? I am making a very simple webview app that places different subpages of a website under different tabs (using tablayout), i.e. messages, orders etc. The individual webviews are created using fragments. The idea is that the user can quickly switch back and forth between pages. While testing, when I switch to the tab directly next to the one I'm on and then back, the page is exactly how it was when I left the tab. However, I switch to a tab that is further than one tab away from the one I'm...
  • u

    user

    07/08/2022, 3:11 PM
    How to verify a top level function was called with Mockk? How to verify that a top level (static) function was called in a test with MockK? Simple approach like: verify { someTopLevelFunction("some text") } results in io.mockk.MockKException: can't find stub kotlin.Unit.
  • u

    user

    07/08/2022, 3:11 PM
    How to reduce the use of viewBinding, to call (text,edit)views From layout I want to decrease the use of binding in my code fun setVisibility() { binding.tvFact.visibility = View.VISIBLE binding.tvTimeStamp.visibility = View.VISIBLE binding.progressBar.visibility = View.GONE }
  • u

    user

    07/08/2022, 3:11 PM
    Converting some code snippet from groovy to kotlin KTS in my build.gradle.kts file I have the following code in my build.gradle.kts. I have now migrated to kotlin KTS. And need help on translating this code from groovy to kotlin script. fun getVersionFromGit(fallback: String): String { return try { if (Os.isFamily(Os.FAMILY_WINDOWS)) { "git describe --tags --abbrev=0 --match "v*.*.*"".execute().text.substring(1).trim() } else { ["sh , "-c"", "git describe --tags --abbrev=0 --match "v*.*.*""].execute().text.substring(1).trim()...
  • u

    user

    07/08/2022, 3:51 PM
    Kotlin Arrays add element via With/let I have these code segments. I want to find the optimal solution and if it's possible some explanation why my 1st piece of code is broken. I have struggled with adding elements to the existing Array, without minimal external stuff. I tried with +=' '.plus(), and.plusElement(), and the only solution I found to work is by coping the current array to MutableList and then adding an element to it. After that, I convert it again to Array and return the right type Array. I am sure that there is a...
  • u

    user

    07/08/2022, 4:11 PM
    how to get the name of subcollection in cloud firestore I have database (Like the image below) and I Need to get the name of subcollection which contain Quiz Name

    enter image description hereâ–¾

  • u

    user

    07/08/2022, 4:11 PM
    How to Make Sense of Dagger Hilt Build Output - Migrating from Dagger 2 to Hilt I'm migrating our app from Dagger 2 to Hilt (I'm pretty new to all of this). I may have bitten off more than I can chew. I have been troubleshooting this for a few days now and I'm not exactly sure how to read the build output. Can someone help makes sense of what these error messages mean? Is there a resource for decoding these errors?
    Task :companyname:kaptDebugKotlin...
  • u

    user

    07/08/2022, 4:31 PM
    Coil Kotlin Uri to Bitmap throws null pointer exception Trying to convert a Uri image file to Bitmap in Kotlin fails with a Null Pointer exception. How can I fix this? var bitmap = remember { mutableStateOf(null)} LaunchedEffect(key1 = "tobitmap") { CoroutineScope(Dispatchers.IO).launch { bitmap.value = uriToBitmap( context, shoppingListScreenViewModel.state.value.imageUri ) } } Image( bitmap = bitmap.value?.asImageBitmap()!!, //Throws exception here contentDescription = "" ) private...
  • u

    user

    07/08/2022, 4:51 PM
    How to provide activity or application context in Hilt to ViewModel? Hello I have a button in recyclerview, I would like to show dialog when in one element of recyclerview the button is clicked. I have done: in Adapter: class SetGoalsAdapter( private val onItemDeleteClicked: (Int) -> Unit, private val onItemRootClicked: (Int) -> Unit, private val onButtonClickedListener: (Int) -> Unit) [...more code...] btnQuestion.setOnClickListener() { onButtonClickedListener(item.id) } in VM: @HiltViewModel...
  • u

    user

    07/08/2022, 4:51 PM
    how can i blur song cover in background of the player activity? I have this player screen in my app, and I want to put the album cover of the song on the background of the screen with a blurred effect, how can i do that? Images:

    my player activityâ–¾

    what i wantâ–¾

  • u

    user

    07/08/2022, 5:11 PM
    how to get a variable in an activity from another activity and make the main activity to use variable after initializing from there ?(kotlin ) my kotlin project has 2 activitis (main , second called : AddPlayer) main activity has a button called "Add a player" that it starts second activity . in second activity i have 2 edit text to get a number and a text from user . after press submit button in second activity , in the main activity i want add these values to my mutablelist but idk how to do it ( i think it crashed because main activity uses those variables before getting values from user) plz guide me . my activity code : class...
  • u

    user

    07/08/2022, 5:11 PM
    How to call inner function inside composable? I have a suspend inner function inside a composable but it throws a compile time error stating that the method name cannot be resolved. Why is it not working?
  • u

    user

    07/08/2022, 5:31 PM
    Jetpack Compose Playground is there any online playground for jetpack compose? where I can test and learn jetpack compose. Like https://play.kotlinlang.org Android studio is not lite. It takes time for setting up projects. Every little practice takes lots of time. If there is an online playground, it will be very help full. Thanks.
  • u

    user

    07/08/2022, 6:11 PM
    What does "activity?." mean in Kotlin? I am trying to use a code snippet from the official android documentation (https://developer.android.com/training/printing/photos#kotlin) which is the doPhotoPrint() function in the code that I have attached, in order to learn how to use the PrintHelper class in Kotlin and Android Studio. See the attached image of the the code snippet: <a href="

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

    "...
  • u

    user

    07/08/2022, 7:51 PM
    Annotate one of the constructors for a class with non-nullable parameters in Kotlin I want to use MapStruct to create a mapper from Kotlin Code. The mapper should map to the class with non-nullable fields. data class TargetClass(val nonNullable: String, var canBeNullable: Int? = null) For that I would expect MapStruct use constructor: TargetClass targetClass = new TargetClass("someString"); targetClass.setCanBeNullable = 3; With MapStruct I believe I can do it by annotating one of the constructors with @Default annotation. I can annotate the whole with @JvmOverloads and...
  • u

    user

    07/08/2022, 8:31 PM
    Multimodule app finish previous Activity when navigate to another Activity I have a project with different modules. I got :ft_a and :ft_b and they don't know about each other. There is a case where I want to go from :ft_a to :ft_b that I am using the Navigation component, so I use the ActivityNavigator library. When I navigate from A (in :ft_a) to B (in :ft_b), I want to finish Activity A. For this, I tried to use the popBackStack() function like the...
  • u

    user

    07/08/2022, 8:51 PM
    Excluding New Dependencies in Gradle File I have an app that runs perfectly without new dependencies like this one: A newer version of androidx.navigation:navigation-fragment-ktx than 2.4.2 is available: 2.5.0 If I upgrade to v.2.5.0, my app has warnings about unrelated elements like for example references to menu objects. Should I wait and allow these Gradle warnings such as above notice until another upgrade comes along and try the new dependency then?
  • u

    user

    07/08/2022, 8:51 PM
    It only works once in expandable recyclerview using epoxy I'm making an expandable Nested RecyclerView using Epoxy. made it to some extent, but the problem is that when I press the expand button, it expands, but it doesn't come back. I'm not sure where I went wrong. What's wrong? ParentItem data class ParentItem( val workout: String="sex", val list: List, // Child Item val isExpandable : Boolean = false ) ParentEpoxyController class ParentEpoxyController : EpoxyController() { private lateinit var data : List override fun...
  • u

    user

    07/08/2022, 9:31 PM
    Equalizer stops 10 seconds after exiting the fragment I am a beginner in the world of programming, and now I am working on developing an audio player by adding an equalizer, but I encountered a problem, which is after 10 seconds of pressing the back button and exiting the fragment, the equalizer stops and does not work until after opening the page again. Also, when playing another audio, the equalizer stops and does not work until the fragment is opened again. I have tried to fix it but to no avail, Plz Help.. public class MainActivityEqualizer...
  • u

    user

    07/08/2022, 9:51 PM
    Interstitial ad not showing using .setOnClickListener Method Kotlin i am trying to show interstitial ad when user click Buttons on my Kotlin app but the ad never shows. this is my Fragment layout when button exist "item_frag_installed_app.xml" this is my AppInstalledAdapter.kt when .setOnClickListener method only exist. private var interstitialAd: MaxInterstitialAd? = null override fun updateView(dateItem: AppInfo) { super.updateView(dateItem) ImageLoader.Builder(mContext, AppedIconUrl(dateItem.packageName,...
  • u

    user

    07/08/2022, 10:51 PM
    Trying to make my alarm manager alarm clock, survive force closing the app How do I make my alarm manager alarms that are set, not get erased after clearing all my running apps from memory.
  • u

    user

    07/09/2022, 1:11 AM
    Uri to scaled Bitmap Kotlin code displays the image rotated on its side I have Kotlin code that scales down the Uri image to a Bitmap and back to a Uri. Although the code successfully scales the image, it displays it rotated onto its side. What could be wrong with the code? Composable LaunchedEffect(key1 = "tobitmaps") { uriResult.value = resizeImage( context, viewModel.state.value.imageUri ) } uriResult.value?.let { imageUri -> AsyncImage( imageUri, contentDescription = null, modifier =...
  • u

    user

    07/09/2022, 3:11 AM
    Migrate from Kotlin Syntetic to Kotlin ViewBinding in Android Studio [duplicate] How do I implement viewbinding on a kotlin class?, I'm having trouble implementing this in this code: package com.example.audio.manager.view import android.content.Context import com.example.audio.manager.model.MyAudio import com.example.audio.manager.R import kotlinx.android.synthetic.main.view_myaudio.view.* line to remove @Suppress("DEPRECATION") class MyAudioView : LinearLayout, View.OnClickListener, SeekBar.OnSeekBarChangeListener, MyAudioManagerListener { private fun init() {...
  • u

    user

    07/09/2022, 4:11 AM
    My addOnSuccessListener code is being skipped Firestore / Kotlin I made a function that returns an object built with Firestore document fields but my code in addOnSuccessListener is being skipped (I've checked that with debug and Logs) It simply jumps from the 'db.collection....' to the end fun getPostObj(collection : String, document : String, db : FirebaseFirestore) : Post{ val newPostOb = Post() db.collection(collection).document(document).get().addOnSuccessListener { newPostOb.title = it.getString("title") newPostOb.body =...
Powered by Linen
Title
u

user

07/09/2022, 4:11 AM
My addOnSuccessListener code is being skipped Firestore / Kotlin I made a function that returns an object built with Firestore document fields but my code in addOnSuccessListener is being skipped (I've checked that with debug and Logs) It simply jumps from the 'db.collection....' to the end fun getPostObj(collection : String, document : String, db : FirebaseFirestore) : Post{ val newPostOb = Post() db.collection(collection).document(document).get().addOnSuccessListener { newPostOb.title = it.getString("title") newPostOb.body =...
View count: 3