# StackOverflowError with data binding lambda expression

**URL:** https://discuss.kotlinlang.org/t/stackoverflowerror-with-data-binding-lambda-expression/2115
**Category:** Android
**Created:** [November 25, 2016, 4:02am UTC](https://discuss.kotlinlang.org/t/stackoverflowerror-with-data-binding-lambda-expression/2115 "2016-11-25T04:02:00Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![harrypotter](https://avatars.discourse-cdn.com/v4/letter/h/ee7513/32.png) [@harrypotter](https://discuss.kotlinlang.org/u/harrypotter)
#### Post date: [November 25, 2016, 4:02am UTC](https://discuss.kotlinlang.org/t/stackoverflowerror-with-data-binding-lambda-expression/2115/1 "2016-11-25T04:02:00Z")

</div>

Hi,

I have a few lambda expression already. But I try to add one for android:onLongClick. But the build fails

> error: cannot generate view binders java.lang.StackOverflowError  
> at android.databinding.tool.writer.LayoutBinderWriterKt$callbackLocalName$2.invoke(LayoutBinderWriter.kt)  
> at android.databinding.tool.writer.LayoutBinderWriterKt$callbackLocalName$2.invoke(LayoutBinderWriter.kt)  
> at android.databinding.tool.ext.LazyExt.getValue(ext.kt:27)  
> at android.databinding.tool.writer.LayoutBinderWriterKt.getCallbackLocalName(LayoutBinderWriter.kt)  
> at android.databinding.tool.writer.LayoutBinderWriterKt.scopedName(LayoutBinderWriter.kt:200)  
> at android.databinding.tool.expr.Expr.toCode(Expr.java:739)  
> at android.databinding.tool.writer.LayoutBinderWriterKt$callbackLocalName$2.invoke(LayoutBinderWriter.kt:206)  
> at android.databinding.tool.writer.LayoutBinderWriterKt$callbackLocalName$2.invoke(LayoutBinderWriter.kt)  
> at android.databinding.tool.ext.LazyExt.getValue(ext.kt:27)  
> at android.databinding.tool.writer.LayoutBinderWriterKt.getCallbackLocalName(LayoutBinderWriter.kt)  
> at android.databinding.tool.writer.LayoutBinderWriterKt.scopedName(LayoutBinderWriter.kt:200)  
> at android.databinding.tool.expr.Expr.toCode(Expr.java:739)

…you get the picture  
Now in the layout I have the activity bound and try to set android:onLongClick, this should be supported

```
<data>
    <variable name="context" type="letstwinkle.com.twinkle.ProspectsActivity" />
    <variable name="quiz" type="letstwinkle.com.twinkle.model.ProspectQuiz" />
</data>
    <TextView
        android:onLongClick="@{() -> context.quizLongClicked(quiz)}"
        />

```

I bind this attribute in one other layout like this:

```
        android:onLongClick="@{activity::matchPlayAvatarLongPressed}"

```

So seems like method reference is OK, but Kotline not handling a lambda properly for a synthetic attribute? Plus similar expression for android:onClick works.

---

<div class="post-metadata">

### Author: ![yole](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/yole/32/1425_2.png) [@yole](https://discuss.kotlinlang.org/u/yole)
#### Post date: [November 25, 2016, 9:46am UTC](https://discuss.kotlinlang.org/t/stackoverflowerror-with-data-binding-lambda-expression/2115/2 "2016-11-25T09:46:10Z")

</div>

This is an issue with the databinding compiler, not with Kotlin. The Kotlin compiler is not involved in any way with compiling the databinding expressions in layout XML files.

---

<div class="post-metadata">

### Author: ![harrypotter](https://avatars.discourse-cdn.com/v4/letter/h/ee7513/32.png) [@harrypotter](https://discuss.kotlinlang.org/u/harrypotter)
#### Post date: [November 25, 2016, 9:35pm UTC](https://discuss.kotlinlang.org/t/stackoverflowerror-with-data-binding-lambda-expression/2115/3 "2016-11-25T21:35:00Z")

</div>

So the class android.databinding.tool.writer.LayoutBinderWriterKt. is implemented by the data binding library developers?

---

<div class="post-metadata">

### Author: ![yole](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/yole/32/1425_2.png) [@yole](https://discuss.kotlinlang.org/u/yole)
#### Post date: [November 26, 2016, 6:45am UTC](https://discuss.kotlinlang.org/t/stackoverflowerror-with-data-binding-lambda-expression/2115/4 "2016-11-26T06:45:03Z")

</div>

Yes.

---

<div class="post-metadata">

### Author: ![francois\_blavoet](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/francois_blavoet/32/1710_2.png) [@francois\_blavoet](https://discuss.kotlinlang.org/u/francois_blavoet)
#### Post date: [November 27, 2016, 2:07pm UTC](https://discuss.kotlinlang.org/t/stackoverflowerror-with-data-binding-lambda-expression/2115/5 "2016-11-27T14:07:23Z")

</div>

hmm

I think you just have an error in your xml :  
1 - Does quizLongClicked return a boolean ?  
2 - have you tried using something else than context for your variable name ? databinding already allows you to use context in order to refer to root.context, so it sounds like naming your variable context can only lead to issues.

(and that would not work in java either)

---

<div class="post-metadata">

### Author: ![harrypotter](https://avatars.discourse-cdn.com/v4/letter/h/ee7513/32.png) [@harrypotter](https://discuss.kotlinlang.org/u/harrypotter)
#### Post date: [December 7, 2016, 3:24am UTC](https://discuss.kotlinlang.org/t/stackoverflowerror-with-data-binding-lambda-expression/2115/6 "2016-12-07T03:24:56Z")

</div>

After checking, I found a signature error. I updated the method, stopped getting the SO error.
