Questions tagged [kotlin]

Kotlin is an open-source, statically typed programming language supported and developed by JetBrains. Kotlin combines OOP and functional features and is focused on interoperability, safety, clarity, and tooling support. It currently targets the JVM, JavaScript and native targets, and it's an officially supported language on Android.

Kotlin is an open-source, statically typed programming language supported and developed by JetBrains. It supports JVM bytecode, JavaScript, and Native code as compilation targets, and it has been an officially supported first-class language on Android since Google I/O 2017. The goals with Kotlin are to make it concise, safe, versatile, and have it be seamlessly interoperable with existing Java libraries.

On May 5, 2021, The Kotlin team released version 1.5 (announcement / github release tag).

The current major version is 1.5.

How to ask

If you are using Kotlin and your question is related to it, then you should add this tag. You should explain what do you intend to achieve, how did you try to achieve it, what the experienced behavior is and how is that different from your expectations.

Kotlin Reference Documentation

Kotlin Books

Development tools

Useful links

57697 questions
14
votes
3 answers

How to fetch resource id in fragment using kotlin in android?

I tried to this code which is mention below, but getting crash during run time. The error occurred is Android Run time: FATAL EXCEPTION: main Process: com.root.specialbridge,…
Ramesh
  • 1,382
  • 2
  • 10
  • 15
14
votes
2 answers

Android Studio - java.io.IOException: Failed to generate v1 signature

I get this error after updating my Android Studio to all new versions after 3.0 Canary 4. (I am using v3.0 cause it is much faster and there is no need to jack for Kotlin.) It looks like there is an issue with build flow that it cannot generate or…
Mohsen Mirhoseini
  • 6,605
  • 4
  • 25
  • 53
14
votes
3 answers

Kotlin: conditional items during map creation

Is there a way to do something like this in Kotlin? mapOf( "key1" to var1, "key2" to var2, if(var3 > 5) "key3" to var3 ) Or the only way is to add the key "key3" after the map is created? I'd like to add an item to a map only if…
Aleš Zrak
  • 361
  • 1
  • 3
  • 14
14
votes
6 answers

Using room as singleton in kotlin

I'm trying to use Room as singleton so I didn't have to invoke Room.databaseBuilder() -which is expensive- more than once. @Database(entities = arrayOf( Price::class, StationOrder::class, TicketPrice::class, …
humazed
  • 66,202
  • 30
  • 86
  • 124
14
votes
2 answers

Clean Architecture: Use different model classes for different data sources?

I am currently developing a news feed android app. I try to design my app according to the principles of clean architecture. In the data layer I am using the repository pattern as a facade for the diferent data sources: remote data from an API…
Elias
  • 473
  • 3
  • 18
14
votes
2 answers

How to call outer class' super method from inner class in Kotlin?

What is the Kotlin equivalent of Java's OuterClass.super.method()? Example (in Java): class Outer { class Inner { void someMethod() { Outer.super.someOtherMethod(); } } @Override public String…
Siegmeyer
  • 3,340
  • 3
  • 18
  • 36
14
votes
2 answers

Padding string in Kotlin

I was trying to pad a string in Kotlin to achieve some proper alignment on the console output. Something along these lines: accountsLoopQuery - "$.contactPoints.contactPoints[?(@.contactAccount.id)]" brokerPassword …
gil.fernandes
  • 9,585
  • 3
  • 41
  • 57
14
votes
2 answers

kotlin extension method access in another kt

I'm thinking about adding a global extension method to String in just one file,and wherever i use a String i can always use this extension. But i failed to find a way to do so...i just paste the extension everywhere now. extension here in…
Draculea
  • 153
  • 1
  • 7
14
votes
2 answers

kotlin lambda expressions as optional parameter

How can I pass lambda expression as optional parameter in Kotlin language val max = { a: Int, b: Int -> if (a > b) a else b } I have to pass above thing is like optional parameter
Prathap
  • 299
  • 2
  • 11
14
votes
3 answers

Convert String obtained from edittext to Integer in Kotlin language

I am trying to make a simple Android application using Kotlin language. I have one EditText, I am getting its value in String but I want to convert that value into an integer. How can I convert this string to integer in Kotlin language?.
Manish
  • 740
  • 1
  • 10
  • 19
14
votes
2 answers

Why Kotlin receives such an UndeclaredThrowableException rather than a ParseException?

I have an extension method that converts string to Date in Kotlin. fun String.convertToDate() : Date { var pattern: String = "dd-mm-yyyy" val dateFormatter = SimpleDateFormat(pattern) return dateFormatter.parse(this) // parse method throw…
seal
  • 1,002
  • 3
  • 17
  • 35
14
votes
3 answers

Project won't build with Kotlin 1.1.3

I have an Android project that I've recently updated with 1.1.3, and every time I build I get the following error: Error:Execution failed for task ':app:compileDebugJavaWithJavac'. >…
Allan W
  • 2,293
  • 2
  • 16
  • 36
14
votes
2 answers

How to use fragments with kotlin

I can not find how to use fragments using kotlin. I get an error in the onCreateView method, please help me. ListaFragment.kt: class ListaFragment : Fragment() { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,…
14
votes
2 answers

Automatic library version update for Gradle projects is currently unsupported. Please update your build.gradle manually

I have this in my building.gradle buildscript { ext.kotlin_version = '1.1.2-4' ext.kotlin_version = '1.1.2' repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.3.3' …
Eder Padilla
  • 1,067
  • 1
  • 9
  • 17
14
votes
2 answers

Expression cannot be a selector (occur after a dot) in Kotlin

I am using Kotlin library to code my android app. I have one activity with one button. I have set click listener on it, I am displaying a toast on clicking on button. import android.os.Bundle import android.support.v7.app.AppCompatActivity import…
N Sharma
  • 28,073
  • 81
  • 228
  • 405
1 2 3
99
100