Unresolved reference for synthetic view when layout is in library module

Update: Synthetic view references have been deprecated and will not be supported in the future. The current recommended solution is to use ViewBinding (or wait for Jetpack Compose) Original Answer: One way to solve this is to create an “alias” property that can be consumed from other modules: // SyntheticExports.kt package com.example.synthetic.exported import kotlinx.android.synthetic.main.layout_in_library.* inline … Read more

This type has a constructor and must be initialized here – Kotlin

This is not about primary/secondary constructors. On JVM (and pretty much anywhere else) a constructor of the base class Application is called when you create an instance of SomeApp In Java the syntax is like you said: class SomeApp : Application { constructor SomeApp(){ super(); } } Here you must declare a constructor, and then … Read more

Kotlin Android debounce

I’ve created a gist with three debounce operators inspired by this elegant solution from Patrick where I added two more similar cases: throttleFirst and throttleLatest. Both of these are very similar to their RxJava analogues (throttleFirst, throttleLatest). throttleLatest works similar to debounce but it operates on time intervals and returns the latest data for each … Read more

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

The build.gradle snippet you posted looks like the config inside your app module. What does the build.gradle in your project’s root directory look like? To add the kotlin plugin dependencies it should look something like this: buildscript { ext.kotlin_version = ‘1.6.10’ repositories { jcenter() google() } dependencies { classpath ‘com.android.tools.build:gradle:3.0.0-beta6’ classpath “org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version” // NOTE: Do … Read more

how to instantiate ViewModel In AndroidX?

Updated answer: Things changed a little bit, as the previously needed dependency – ViewModelProviders – got deprecated (see the old answer for details). You can now use the ViewModelProvider constructor directly. So, in this case, the answer would be: private val viewModel = ViewModelProvider(this).get(SheduleViewModel::class.java) Note that, however, if you include the androidx.activity:activity-ktx:$Version dependency (a few … Read more

Kotlin Activity cannot be extended. This type is final, so it cannot be inherited

As per Kotlin documentation, open annotation on a class is the opposite of Java’s final. It allows others to inherit from this class. By default, all classes in Kotlin are final. open class Base { open fun v() {} fun nv() {} } class Derived() : Base() { override fun v() {} } Refer :https://kotlinlang.org/docs/reference/classes.html

How to Pass custom object via intent in kotlin

First, make sure the People class implements the Serializable interface: class People : Serializable { // your stuff } Inner fields of People class must also implement the Serializable interface, otherwise you’ll get runtime error. Then it should work: fun launchNextScreen(context: Context, people: People): Intent { val intent = Intent(context, NextScreenActivity::class.java) intent.putExtra(EXTRA_PEOPLE, people) return intent … Read more

Kotlin Remove all non alphanumeric characters

You need to create a regex object var answer = “Test. ,replace” println(answer) answer = answer.replace(“[^A-Za-z0-9 ]”, “”) // doesn’t work println(answer) val re = Regex(“[^A-Za-z0-9 ]”) answer = re.replace(answer, “”) // works println(answer) Try it online: https://try.kotlinlang.org/#/UserProjects/ttqm0r6lisi743f2dltveid1u9/2olerk6jvb10l03q6bkk1lapjn

Kotlin synthetic in Adapter or ViewHolder

Simple example from https://github.com/antoniolg/Kotlin-for-Android-Developers import kotlinx.android.synthetic.item_forecast.view.* class ForecastListAdapter() : RecyclerView.Adapter<ForecastListAdapter.ViewHolder>() { class ViewHolder(view: View) : RecyclerView.ViewHolder(view) { fun bindForecast(forecast: Forecast) { itemView.date.text = forecast.date.toDateString() } } } No need to write val view = itemView.findViewById(R.id.date) as TextView view.text = forecast.date.toDateString() Just itemView.date.text = forecast.date.toDateString() Simple and effective!

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)