• 5

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191


File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

I am using data binding in my current application, and so far so good. However, when I tried to use it with a custom data binding adapter I wrote for my custom view, I got an error from auto generated file as the title says, missing return statement. This error does not occur when I used this data binding on only one view, but more than one gives the error. Below are my custom view and adapters, and usage in xml file. I already checked the answer of kinda duplicated question but it doesn't worked in my case, and does not have enough explanation.

class NeonTextView(context: Context, attrs: AttributeSet) : TextView(context, attrs) {

private val drawableClear: Drawable?
    get() = ContextCompat.getDrawable(context, R.drawable.ic_clear)

lateinit var actionMethod: () -> Unit
lateinit var clearMethod: () -> Unit
var hasActionMethod = false
var hasClearMethod = false

init {

private fun setupAttributes(attrs: AttributeSet) {
    val typedArray =
        context.theme.obtainStyledAttributes(attrs, R.styleable.NeonTextView, 0, 0)

    hasActionMethod = typedArray.getBoolean(
    hasClearMethod = typedArray.getBoolean(

override fun onTextChanged(
    text: CharSequence?,
    start: Int,
    lengthBefore: Int,
    lengthAfter: Int
) {
    text?.let { text ->
        drawableClear?.let {
            it.setBounds(0, 0, it.intrinsicWidth, it.intrinsicHeight)
            if (text.isNotEmpty()) drawableClear!! else null,

override fun onTouchEvent(event: MotionEvent?): Boolean {
    event?.let {
        return when (it.action) {
            ACTION_DOWN -> return true
            ACTION_UP -> {
                if (compoundDrawables[2] == null && hasActionMethod) {
                } else {
                    if (it.x > (width - paddingRight - compoundDrawables[2]!!.intrinsicWidth)) {
                        if (hasClearMethod) clearMethod()
                        text = ""
                    } else {
                        if (hasActionMethod) actionMethod()
            else -> false
    }.run {
        return false

override fun performClick(): Boolean {
    return true

And here is my binding adapters for binding methods that are used inside this custom text view:

fun NeonTextView.setActionMethod(actionMethod: () -> Unit) {
    this.actionMethod = actionMethod
    this.hasActionMethod = true

fun NeonTextView.setClearMethod(clearMethod: () -> Unit) {
    this.clearMethod = clearMethod
    this.hasClearMethod = true

And here is how I applied inside xml file:

                        app:actionMethod="@{() -> viewModel.getDepartmentList()}"/>

Any ideas why I am getting error from generated file when I used this binding in more than one view inside xml?

Thanks in advance.

The problem is with Java<->Kotlin compatibility. In Kotlin if you declare function

interface Func {
    fun test(): Unit {

And use it from java

class FuncImpl implements Func {
    public Unit test() {
        return Unit.INSTANCE;

Note, please, that in that case in java code you need return statement. The same is for lambdas. So when you set up lambda from xml using databinding, it's treated as java's lambda, so generated code wasn't correctly processed in that case.

  • 1
Reply Report
    • So is there a way to handle the approach currently I am trying? Or is it just a dead end, which needs to be handled by code?
      • 2
    • it calls following piece of code: private fun executeQuery(token: String, query: String) { sqlQueryUseCase(SqlQueryUseCase.Params(token, query)) { it.either(::handleErrorState, ::onDataListFetched) } } which one is a network call to a REST api, and retrieve the list from response and set to a MutableLiveData on view model itself.