Questions related to Kotlin Android Extensions
Questions tagged [kotlin-android-extensions]
721 questions
267
votes
9 answers
NullPointerException when trying to access views in a Kotlin fragment
How to use Kotlin Android Extensions with Fragments?
If I use them inside onCreateView(), I get this NullPointerException exception:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual
method 'android.view.View…

solidak
- 5,033
- 3
- 31
- 33
189
votes
42 answers
Error: Execution failed for task ':app:clean'. Unable to delete file
I'm trying to rebuild my Android Studio Gradle project (containing mostly Kotlin code), but it started to throw an UnableToDeleteFileException during the cleaning/rebuilding process:
Execution failed for task ':app:clean'.
> Unable to delete file:…

Bryony
- 2,209
- 2
- 11
- 12
171
votes
15 answers
Outdated Kotlin Runtime warning in Android Studio
After downloaded and installed latest Kotlin plugin I have Outdated Kotlin Runtime warning from Android Studio that telling me:
Your version of Kotlin runtime in 'kotlin-stdlib-1.1.2' library is
1.1.2, while plugin version is…

Arsenius
- 4,972
- 4
- 26
- 39
152
votes
21 answers
Unresolved reference: kotlinx
I am trying to try out Kotlin and the Kotlin Android extensions in Android Studio. I have tried this both in Android Studio v 1.5.1 on Ubuntu 14.04, and in Android Studio v 1.5.1 on OS X El Capitan with the same result.
Here is what I am doing:
I…

nPn
- 16,254
- 9
- 35
- 58
143
votes
13 answers
how to get viewModel by viewModels? (fragment-ktx)
I am working with Single viewModel for the Activity and all of its fragment.
So to initialise viewmodel if have to write this setup code in onActivityCreated of all the fragment's
override fun onActivityCreated(savedInstanceState: Bundle?) {
…

Anmol
- 8,110
- 9
- 38
- 63
123
votes
6 answers
How to add an item to an ArrayList in Kotlin?
How to add an item to an ArrayList in Kotlin?

Ramesh
- 1,772
- 4
- 12
- 15
116
votes
5 answers
What's Kotlin Backing Field For?
As a Java developer, the concept of a backing field is a bit foreign to me. Given:
class Sample {
var counter = 0 // the initializer value is written directly to the backing field
set(value) {
if (value >= 0) field = value
…

Yudhistira Arya
- 3,491
- 6
- 25
- 42
105
votes
4 answers
ViewBinding vs Kotlin Android Extensions with synthetic views
How does the new ViewBinding compare with the Kotlin Android Extensions with synthetic views bindings?
Apart from the NullSafety and TypeSafety provided by new ViewBindings, why should we consider ditching the Kotlin way of using synthetic bindings…

Rinav
- 2,527
- 8
- 33
- 55
101
votes
7 answers
How to add an item to a list in Kotlin?
I'm trying to add an element list to the list of string, but I found Kotlin does not have an add function like java so please help me out how to add the items to the list.
class RetrofitKotlin : AppCompatActivity() {
var…

Mohit Lakhanpal
- 1,309
- 3
- 11
- 19
100
votes
7 answers
Accidental override: The following declarations have the same JVM signature
I'm getting error in Kotlin in this part:
class GitHubRepoAdapter(
private val context: Context,
private val values: List
) : ArrayAdapter(
context,
R.layout.list_item,
values
)
private val context:…

Ege Kuzubasioglu
- 5,991
- 12
- 49
- 85
88
votes
7 answers
Kotlin synthetic in Adapter or ViewHolder
I am new in kotlin. I have found and tried to use synthetic method instead of annoying method findViewById in my Activity class, but I have found "If we want to call the synthetic properties on View (useful in adapter classes), we should also import…

busylee
- 2,540
- 1
- 16
- 35
75
votes
8 answers
Kotlin Remove all non alphanumeric characters
I am trying to remove all non alphanumeric characters from a string.
I tried using replace() with a regex as followed:
var answer = answerEditText.text.toString()
Log.d("debug", answer)
answer = answer.replace("[^A-Za-z0-9 ]",…

Distwo
- 11,569
- 8
- 42
- 65
69
votes
9 answers
How to Pass custom object via intent in kotlin
fun launchNextScreen(context: Context, people: People): Intent {
val intent = Intent(context, NextScreenActivity::class.java)
intent.putExtra(EXTRA_PEOPLE, (Parcelable) people)
//intent.putExtra(EXTRA_PEOPLE, people as Parcelable)
…

Ankit Kumar
- 3,663
- 2
- 26
- 38
69
votes
4 answers
Kotlin Activity cannot be extended. This type is final, so it cannot be inherited
I have created a Kotlin Activity, but I am not able to extend the activity. I am getting this message: This type is final, so it cannot be inherited from. How to remove final from Kotlin's activity, so it can be extended?

Logo
- 1,366
- 2
- 11
- 16
68
votes
10 answers
how to instantiate ViewModel In AndroidX?
I want to initialize ViewModel in Activity using androidx library
I have tried what documentation says but it is not working. the ".of" is not resolved.
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import…

Nurseyit Tursunkulov
- 8,012
- 12
- 44
- 78