Skip to main content
The 2024 Developer Survey results are live! See the results

Questions tagged [kotlin]

Kotlin is a cross-platform, statically typed, general-purpose high-level programming language with type inference. This tag is often used alongside additional tags for the different targets (JVM, JavaScript, native, etc.) and libraries/frameworks (Android, Spring, etc.) used by Kotlin developers, if the question relates specifically to those topics.

kotlin
1104 votes
30 answers
577k views

What is the equivalent of Java static methods in Kotlin?

There is no static keyword in Kotlin. What is the best way to represent a static Java method in Kotlin?
pdeva's user avatar
  • 44.9k
1068 votes
29 answers
372k views

Place cursor at the end of text in EditText

I am changing the value of an EditText on keyListener. But when I change the text the cursor is moving to the beginning of the EditText. I need the cursor to be at the end of the text. How to move ...
Manu's user avatar
  • 10.7k
885 votes
23 answers
559k views

Unfortunately MyApp has stopped. How can I solve this?

I am developing an application, and everytime I run it, I get the message: Unfortunately, MyApp has stopped. What can I do to solve this? About this question - obviously inspired by What is a ...
nhaarman's user avatar
  • 100k
873 votes
8 answers
384k views

How to check if a "lateinit" variable has been initialized?

I wonder if there is a way to check if a lateinit variable has been initialized. For example: class Foo() { private lateinit var myFile: File fun bar(path: String?) { path?.let { ...
Mathew Hany's user avatar
  • 13.9k
860 votes
33 answers
472k views

Kotlin Ternary Conditional Operator

What is the equivalent of this expression in Kotlin? a ? b : c This is not valid code in Kotlin.
Drew Noakes's user avatar
787 votes
38 answers
272k views

Cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6

When trying to run the Example CorDapp (GitHub CorDapp) via IntelliJ, I receive the following error: Cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target ...
Joel's user avatar
  • 23.1k
612 votes
15 answers
425k views

How to make an Android device vibrate? with different frequency?

I wrote an Android application. Now, I want to make the device vibrate when a certain action occurs. How can I do this?
Billie's user avatar
  • 9,106
572 votes
19 answers
560k views

How to launch an Activity from another Application in Android

I want to launch an installed package from my Android application. I assume that it is possible using intents, but I didn't find a way of doing it. Is there a link, where to find the information?
Bastian's user avatar
  • 9,735
539 votes
8 answers
423k views

How to convert a Kotlin source file to a Java source file

I have a Kotlin source file, but I want to translate it to Java. How can I convert Kotlin to Java source?
activedecay's user avatar
  • 10.7k
500 votes
8 answers
243k views

Property initialization using "by lazy" vs. "lateinit"

In Kotlin, if you don't want to initialize a class property inside the constructor or in the top of the class body, you have basically these two options (from the language reference): Lazy ...
regmoraes's user avatar
  • 5,389
472 votes
9 answers
118k views

What is the difference between "const" and "val"?

I have recently read about the const keyword, and I'm so confused! I can't find any difference between const and the val keyword, I mean we can use both of them to make an immutable variable, is there ...
Mathew Hany's user avatar
  • 13.9k
429 votes
4 answers
139k views

How does the reified keyword in Kotlin work?

I'm trying to understand the purpose of the reified keyword. Apparently, it's allowing us to do reflection on generics. However, when I leave it out, it works just as fine. When does this make an ...
hl3mukkel's user avatar
  • 5,849
426 votes
65 answers
265k views

Duplicate class in Kotlin Android

I kept on getting an error that there is a duplicate error in classes. This is what I have under org.jetbrains.kotlin folder .idea/libraries It seems like the problem is because there is two different ...
midnighthowlers's user avatar
426 votes
13 answers
184k views

Smart cast to 'Type' is impossible, because 'variable' is a mutable property that could have been changed by this time

And the Kotlin newbie asks, "why won't the following code compile?": var left: Node? = null fun show() { if (left != null) { queue.add(left) // ERROR HERE } } Smart ...
frankelot's user avatar
  • 14.2k
412 votes
27 answers
407k views

How to initialize an array in Kotlin with values?

In Java an array can be initialized such as: int numbers[] = new int[] {10, 20, 30, 40, 50} How does Kotlin's array initialization look like?
Lars Blumberg's user avatar

15 30 50 per page
1
2 3 4 5
6440