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

    07/24/2022, 7:41 AM
    Android Studio: Kotlin Random Number Generator not working? I am using CardView in RecyclerView for displaying a list of City names. Along with the city name, I would like to add a curved square image containing a random background colour and the starting letter of the city name, just like the default image of our Gmail accounts. I have tried the following approach for generating a random index in the colours array and passing the colour to the ViewHolder class of my CustomAdapter. colors.xml #FFBB86FC #FF6200EE #FF3700B3 #FF03DAC5...
  • u

    user

    07/24/2022, 8:01 AM
    Kotlin Infinite Recursion val minesAround = checkIfMinesAround(row, column) if (!minesAround) { explore(row, column) ... private fun explore(row: Int, column: Int) { displayedMinefield[column][row] = Symbol.FCell.symbol for (i in determineRange(column, minefield.lastIndex)) { for (j in determineRange(row, minefield[i].lastIndex)) { displayedMinefield[i][j] = minefield[i][j] if (!checkIfMinesAround(i, j)) {...
  • u

    user

    07/24/2022, 8:21 AM
    How to post a selected image to a python API which will save the filename to mySQL db and then upload the image to an online folder This is my Kotlin code imageButton.setOnClickListener { val gallery = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI) startActivityForResult(gallery, pickImage) } } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) if (resultCode == RESULT_OK && requestCode == pickImage) { imageUri = data?.data imageView.setImageURI(imageUri)...
  • u

    user

    07/24/2022, 9:01 AM
    Failed to initialize detector error in MLkits I want use mlkits in my app for object detection with kotlin but i get this errors E/MobileVisionBase: Error preloading model resource com.google.mlkit.common.MlKitException: Failed to initialize detector. how can i fix?
  • u

    user

    07/24/2022, 9:01 AM
    access child database in firebase always returns null using android studio & kotlin ive been having problems accessing this child database in firebase, it always return null, been searching up online for days and still got no answer...heres my code, im using kotlin and firebase auth = FirebaseAuth.getInstance() database = FirebaseDatabase.getInstance() databaseReference = database?.reference!!.child("users") val nikReference = databaseReference?.child("nik") val mainDB = nikReference?.child("jabatan") val user = auth.currentUser etEmailUserShow.text = user?.email...
  • u

    user

    07/24/2022, 9:21 AM
    Flood Fill Algorithm for Kotlin How would I implement the flood fill algorithm in Kotlin? I'm trying to use it for a two-dimensional array to change the surroundings of certain elements. I'm not using this for painting.
  • u

    user

    07/24/2022, 9:21 AM
    can anyone help me out why I am getting null value even there is no error in the code package com.example.myquizapp import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.util.Log import android.widget.ProgressBar import android.widget.TextView here is my code class QuizActivity : AppCompatActivity() { private var progressBar : ProgressBar?= null private var tvProgress : TextView? = null override fun onCreate(savedInstanceState: Bundle?) { progressBar = findViewById(R.id.progressBar) on hover R.id.progressBar I get...
  • u

    user

    07/24/2022, 9:41 AM
    Uploading png error with MultipartBody.Part and RequestBody in Kotlin I am currently making a project for attendance application in Kotlin and I am trying to send a selfie image to the back-end for proof of attendance. I used MultipartBody.Part to send the image file and RequestBody to send the other stuff. @Multipart @POST("shiftentry/clockin") suspend fun clockin( @Header("Authorization") auth: String, @Part("shift_entry_id") id: RequestBody, @Part("location") location:RequestBody, @Part file: MultipartBody.Part ):...
  • u

    user

    07/24/2022, 10:01 AM
    my app keeps crashing in android studio for some random reason so basically, i am trying to develop an app in android studio but it keeps crashing. I got no idea why. can som1 help? This is the error code below: 2022-07-24 12:45:13.430 9938-9938/com.example.aviationista E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.aviationista, PID: 9938 java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.aviationista/com.example.aviationista.MainActivity}: java.lang.InstantiationException: java.lang.Class cannot be...
  • u

    user

    07/24/2022, 10:21 AM
    I can not open downloaded from the server on android add-on files minecraft I have a task, I need to download from the server add-on files for minecraft (.mcaddon, .mcpack, etc.) on android. For this I use DownloadManager. It downloads the files, but I can't open them in minecraft. I assumed that the problem is in MimeType, tried several solutions (application/x-freearc, application/octet-stream, application/zip, multipart/x-zip, application/x-zip-compressed) they did not work. i attach my code and the link to the file i use. <a...
  • u

    user

    07/24/2022, 10:41 AM
    Can't attach the adapter to the RecyclerView Why can't I attach the adapter to RecyclerView? Just constantly getting W/RecyclerView: No adapter attached; skipping layout Fragment class class Latest : Fragment() { private var mRecyclerView: RecyclerView? = null private var mAdapter: CurrencyAdapter? = null override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { val asd = HashMap() asd.put("asd", 1.2) asd.put("as2d", 3.2) Log.i(TAG, "onCreateView: " +...
  • u

    user

    07/24/2022, 11:01 AM
    Is it safe to use Coroutines runBlocking() inside onDataSetChanged of RemoteViewsFactory? I am trying to fetch some latest movie images and display it in the Android app widgets, As per the requirement the widget should refresh every hour to get the latest movies images. Since I am using coroutines throughout the app, I need to use the existing retrofit services with suspend function to get the data. As per the Android documentation, its safe to do heavy operation inside onDataSetChanged of RemoteViewsFactory So I am using this method itself to fetch data from service instead of...
  • u

    user

    07/24/2022, 11:01 AM
    Query MongoDB Realm array only at first index I need to query MongoDB Realm from synced iOS and Android app. In Swift I can write something like this: let dictionary = realm?.objects(myReamlObject.self) let results = dictionary?.where { $0.senses.glosses.term == "the term I want" } or using predicate: let results = dictionary?.filter("ANY senses.glosses.term == %@", "the term I want") Both work well, but I don't want to check ALL senses.glosses.term. Every entry has (or could have) many senses and many glosses. I would like to...
  • u

    user

    07/24/2022, 11:01 AM
    How to get rid of the resource not found exception when clicked on item view on recycler view and instead of data and activity lauch, it crashes app I have built an app to learn the use of adapter and recycler view. It contains a recycler view and adapter, it uses data class to show data on clicked to an item of the recycler view, but the app crashes on runtime whenever I click on an item of the recycler view and showing java resources not found exception, could any one please help me out from this because I am a newbie to learning and debugging this 2022-07-24 16:00:14.903 11460-11460/com.example.planetapp E/AndroidRuntime: FATAL...
  • u

    user

    07/24/2022, 11:41 AM
    Kotlin Coroutine: Dispatchers inside Flow builder Extension functions that returns save Bitmap to device storage and returns result using sealed and class that represent its state. sealed class RequestStatus { data class Loading(val data: T? = null) : RequestStatus() data class Success(val data: T) : RequestStatus() data class Failed(val error: Exception, val data: T? = null) : RequestStatus() { val message = nullableErrorMsg(error.localizedMessage) } } fun View.createAndStoreScreenshot( appName: String,...
  • u

    user

    07/24/2022, 12:01 PM
    How is a Always on Display for Android coded? My smartphone (Samsung A21s) doesn't supoort the AOD of Samsung. So i tested several apps from the Play store. But I want an app,so i decided to code my own app, which allows me to choose my own background. I want to use the pictures from the gallery. I also want a music control for the AOD. I have a accurate idea of what I want, but I don't know how to code it. Does anybody know, how a AOD is coded? I use Kotlin and I'm working with Android Studio. Thank you for your help
  • u

    user

    07/24/2022, 12:41 PM
    Can you change the color of a textview in a recyclerview adapter after a certain condition is met in Main Activity? I have a basic function that displays the elapsed time every time the button is pressed. I cannot get the logic in MainActivity to transfer to the recyclerview adapter. I simply want the text output color to change to red after the time passes 5 seconds. I have tried to research how to do this for the past week and I cannot find the exact answer. I'm hoping someone can help. I have tried it with and without the boolean in the data class. I wasn't sure if that was required. Here is my code:...
  • u

    user

    07/24/2022, 12:41 PM
    How to implement seat booking in Android? I have this json response from the server: [ { "id": 12767236, "rowNumber": "01", "seatNumber": 1, "status": "taken" }, { "id": 12767237, "rowNumber": "01", "seatNumber": 2, "status": "available" } ... ... ... ] Basically it's a list of seats with a few properties, that's all the data I have. So, question is how do I show the seats and let user pick one like below? What component should I use? <a...
  • u

    user

    07/24/2022, 1:21 PM
    How can I save video to MediaStore by CameraX on Java? I saw this page to learn how to take some video captures and save them to a device. the Android official code: // Create MediaStoreOutputOptions for our recorder val name = "CameraX-recording-" + SimpleDateFormat(FILENAME_FORMAT, Locale.US) .format(System.currentTimeMillis()) + ".mp4" val contentValues = ContentValues().apply {...
  • u

    user

    07/24/2022, 1:41 PM
    Just another error of "Caused by: groovy.lang.MissingMethodException: No signature of method: " I researched on web and found different suggestions and even on stackoverflow some people asked similar questions but I couldn't find an answer that can solve my issue... What makes my build.gradle(app) to give this problem when I try to sync the gradle project? I would like to know what steps I should take in order to fix it. I use Android Studio IDE and Linux Debian os. Code: plugins { id 'com.android.application' id 'org.jetbrains.kotlin.android' } android { compileSdk 32...
  • u

    user

    07/24/2022, 2:01 PM
    Buffer size not large enough Facing this error java.lang.RuntimeException: Buffer not large enough for pixels Error Code Line : - val byteBuffer: ByteBuffer = ByteBuffer.allocate(1024*1024*5) bitmap.copyPixelsToBuffer(byteBuffer) I think its the error is Buffer Capacity is small for my image to copy bitmap but than what is the good approach? How much buffer capacity I must assign to not have the error?
  • u

    user

    07/24/2022, 2:01 PM
    Ktor server, a correct way to receive messages from websocket I'm new in Ktor-server and don't fully understand how web sockets receive messages. I found several solutions in different sources. (try\catch and webscoket blocks are omitted) while(true) way while(true){ val incoming = receiveDeserialized() MessageService.newMessage(incoming) } consumeEach way incoming.consumeEach { frame -> // process frame } flow way incoming.receiveAsFlow().filterIsInstance()...
  • u

    user

    07/24/2022, 2:21 PM
    divide a list in Kotlin by a rule Let's say I have a list of strings which represent people and some properties about them in Kotlin. I know the first element in the list will start with "PSN" prefix and the next list elements will be properties about that person. After X lines I will see "PSN" prefix again and so I'll know this is a new person. I want to group the list elements by the person they belong to. Original list example: val originalList : List = ["PSN Elvis Presley", "elvis property 1", "elvis property 2", "PSN...
  • u

    user

    07/24/2022, 2:21 PM
    android complex ui design for shopping apps I have requirement to implement complex UI design (Main scene for slot machine), so i am making research about the best way to do this.i want to design something like shop and when user take action like buying something and press button the item move to box and box close . where i can start from . i think that i can use unity . but i don't know C++ can i use java with it? i'm android developer.

    https://i.stack.imgur.com/VT07f.jpgâ–¾

  • u

    user

    07/24/2022, 2:41 PM
    What should I add in my code so that every time I check one of the recyclerview items it will display his numer of calories AdapterItem: class AdapterItem( val userList: List): RecyclerView.Adapter() { class ViewHolder(itemView: View):RecyclerView.ViewHolder(itemView){ var numeLista: TextView var caloriiLista: TextView = itemView.findViewById(R.id.caloriiLista) init{ numeLista=itemView.numeLista caloriiLista=itemView.caloriiLista } } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { var itemView =...
  • u

    user

    07/24/2022, 2:41 PM
    Fragment is not getting popped using navigation graph I am building an app where first time it opens fragment1 to get user details and once user forwards to next fragment2, I am saving the details and setting a boolean variable isUserRegistered to true in SharedPreferences so that when the user opens the app next time, he/she will be directly taken to the fragment2. I am using using navigation graph to handle these things. Following is the code: //declared at the top in onCreateView() of fragment val prefs =...
  • u

    user

    07/24/2022, 3:01 PM
    Kotlin: Styling Text in Snackbar with SDK later than 28 I am working on a Kotlin project and I wish to style the text in a Snackbar, specifically the text font. I have been to many websites that address this problem, but they all use this line in the Snackbar body: val snackbarTextView = snackbar.view.findViewById(android.support.design.R.id.snackbar_text) as TextView The problem setting the TextView with this code, is that it only works if your project targets SDK 28 or older, and legacy libraries are enabled. I am targeting SDK 30 and then the...
  • u

    user

    07/24/2022, 3:21 PM
    Google wallet is not working Android kotlin I am trying to create an application like this to save my ticket passes in google wallet https://codelabs.developers.google.com/add-to-wallet-android#0. I have done all steps but I couldn't get the result.

    Google pay button is not visibleâ–¾

    Actually, I have a google pay on my mobile but it shows "Unfortunately google...
  • u

    user

    07/24/2022, 3:21 PM
    how to synchronise room database of android app with remote server I'm working on an android app with an MVVM pattern. I have to sync my local database with a remote server. but I have no idea how to do it. I have used the room database.
  • u

    user

    07/24/2022, 4:01 PM
    How get app list that user using in phone with UsageStatsManager? I am using UsageStatsManager for track app usage time in kotlin. The problem is I just get user installed app list, but I want to also track using the default downloaded apps (Google Chrome, Youtube, etc. not other system apps) My code is below: val currentTime = System.currentTimeMillis() // The
    queryEvents
    method takes in the
    beginTime
    and
    endTime
    to retrieve the usage events. // In our case, beginTime = currentTime - 10 minutes ( 1000 * 60 * 10 milliseconds )...
Powered by Linen
Title
u

user

07/24/2022, 4:01 PM
How get app list that user using in phone with UsageStatsManager? I am using UsageStatsManager for track app usage time in kotlin. The problem is I just get user installed app list, but I want to also track using the default downloaded apps (Google Chrome, Youtube, etc. not other system apps) My code is below: val currentTime = System.currentTimeMillis() // The
queryEvents
method takes in the
beginTime
and
endTime
to retrieve the usage events. // In our case, beginTime = currentTime - 10 minutes ( 1000 * 60 * 10 milliseconds )...
View count: 3