Categories
Development Kotlin

java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child’s parent first.(Android/Kotlin)

I am receiving the above error on my Alert dialog but not sure why or how to fix it. I believe it stems from the function below. Basically when In my app, navigate to the detail fragment then click the send button in the app to share an SMS the app crashes. please take a […]

Categories
Development Kotlin

Gradle builds jar from Kotlin without dependencies

I am building a jar for an AWS Lambda function. The code is written in Kotlin under src/main/kotlin/com/serverless I need to build a shadow jar that includes the AWS dependencies. Currently the jar does not contain any dependencies. buildscript { repositories { mavenCentral() jcenter() maven { url “https://plugins.gradle.org/m2/” } } dependencies { classpath “org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.61” classpath […]

Categories
Development Kotlin

Setting up Spek test for http methods using Kotlin?

How do I spin up a spek test using kotlin to test whether or not an HTTP method post has been called? Whats tripping me out is i’m having trouble mocking up the context. I’d like to pass in a method other then HttpMethod.POST to fire off the else block. Currently fails with the message […]

Categories
Development Kotlin

Kotlin replaceWith an invoke operator

I have an interface where I would like to notify users to use invoke operator instead of oldFunction. interface SomeInterface { operator fun invoke(param: A) @Deprecated(“Old stuff”, ReplaceWith(“invoke(param)”)) fun oldFunction(param: A) } This currently works, but it replaces the oldFunction with invoke call in place. What I would like is to have it replace the […]

Categories
Development Kotlin

Setting up Spek test for http methods using Kotlin?

How do I spin up a spek test using kotlin to test whether or not an HTTP method post has been called? Whats tripping me out is i’m having trouble mocking up the context. I’d like to pass in a method other then HttpMethod.POST to fire off the else block. Currently fails with the message […]

Categories
Development Kotlin

Kotlin – Check if an object implements a specific interface

Say I have some data class like: data class NameCreated( val index: Float, val name: String ) : ESEventPayload I then have some method where I want to return true if the Event’s type in <Event<out Any>> is implementing ESEventPayload. So for example: fun isItUsing(message: AcknowledgeableMessage<Event<out Any>>): Boolean = I was hoping something like this […]

Categories
Development Kotlin

How to write color id in MainActivity? (Kotlin)

I’m trying to change the button color using this line of code: button.setTextColor(R.color.erik_secundario) But it doesn’t work. So I also read about using that: getResources().getColor(R.color.example_color) And the problem is that i don’t know where i need to implement that code to solve the problem. Thanks!

Categories
Development Kotlin

How to generate a random double value in a specific range in Android Studio using Kotlin?

How do I generate a random number in a specifc float range (From 51.3257 to 52.4557 for example) using Kotlin? var xCoord = randomValue() var yCoord = randomValue() Do I need to make a method or do I just import something?

Categories
Development Kotlin

How do I open Kotlin file from GitHub in Intellij Idea?

I wrote code that works, I uploaded whole project file on GitHub, and when I download it again (with link), I can’t run my code. How can I solve that?

Categories
Development Kotlin

kotlin Get random string from array

New to kotlin and quite a few questions and answers, mostly in Java. After following the documentation and verifying against numerous SO questions/answers Android Studio is complaining about the following in a function. The function is fun getRandomQuote() { val randomValue = Random.nextInt(quotes.size) //return quotes[randomValue] return quotes.get(randomValue) } quotes is an arrayOf(strings) val quotes = […]