Questions tagged [kotlin-android-extensions]

Questions related to Kotlin Android Extensions

Kotlin Android Extensions

665 questions
257
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
  • 4,693
  • 3
  • 25
  • 31
176
votes
41 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:…
164
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
  • 3,049
  • 2
  • 17
  • 21
133
votes
15 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
  • 14,430
  • 8
  • 28
  • 50
100
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
  • 2,762
  • 4
  • 21
  • 39
95
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,382
  • 2
  • 10
  • 15
92
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,169
  • 7
  • 29
  • 48
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,360
  • 1
  • 13
  • 32
78
votes
7 answers

how to get viewModel by viewModels? (fragment-ktx)

I am working with Single viewModel for the Activity and all of it's fragment. So to initialise viewmodel if have to write this setup code in onActivityCreated of all the fragment's override fun onActivityCreated(savedInstanceState: Bundle?) { …
73
votes
3 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,000
  • 10
  • 38
  • 76
58
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,276
  • 2
  • 20
  • 36
58
votes
3 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,112
  • 2
  • 7
  • 15
52
votes
6 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
  • 869
  • 2
  • 7
  • 16
52
votes
3 answers

Error:(1, 0) Plugin with id 'kotlin-android-extensions' not found

apply plugin: 'kotlin-android-extensions'. When i add this extensions in android studio preview, give me this error "Error:(1, 0) Plugin with id 'kotlin-android-extensions' not found.". My build gradle apply plugin:…
46
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
  • 10,755
  • 7
  • 38
  • 60
1
2 3
44 45