35

I'm repairing my friend's code and got confused.
My friend wants to fetch entered text (in EditText). Seems easy, right? Well, it is but instead of user input, he gets this warning/error:
enter image description here

To be honest I'm not sure how to fix it. He is coding in Kotlin (Android 10).
Activity that contains EditText: enter image description here

And XML:
enter image description here

This is how it looks when debugging:
enter image description here

The app started working just fine after running "File -> invalidate Cashes/Restart" option, I just don't understand where this warning came from and how to fix it because the error remained unchanged (even though the app works). Do you have an idea how to solve it?

All the best!

Macieg
  • 558
  • 1
  • 6
  • 9

3 Answers3

49

fyi lambda expression like setOnClickListener from kotlin is not debuggable, see here.

if you want to debug variables inside setOnClickListener you should use the normal one e.g. setOnClickListener(object: View.OnClickListener {..})

nashihu
  • 750
  • 7
  • 17
10

I understand that the question is regarding evaluating expression, but there is a way you can read variables from your debugger console, even if you're inside an anonymous callback. I found it helpful sometimes. Here are the steps:

  • First enter debugger mode inside of your anonymous callback,
  • In your debugger console, look at the right side for "Frames"
  • Within Frames under main, you'll see stack of function execution first top one on the list is the latest: enter image description here
  • Click on row(s) below the latest function, until you find an instance of your activity AddInformationActivity. You will see the activity instance on the right side window under Variables. Don't go as far as selecting functions browned out, because those are from internal libraries.
  • When you see you AddInformationActivity instance, you can expand it and see its variables.

Hope that helps!

Red M
  • 2,609
  • 3
  • 30
  • 50
  • 2
    This should be the acceptable answer. Everyone please upvotes to push the answer to the top of post. Very helpful. Thank you!! – Thái Quốc Toàn Jan 31 '23 at 04:33
  • This works. for observer onChanged has this object. And the combination of mark object (in debugger) will help in reviewing the data from activity or fragment or from where lambda was called. – Shubham AgaRwal Feb 20 '23 at 11:49
  • @ShubhamAgaRwal can you rephrase or explain further, I didn't understand – Red M Feb 20 '23 at 14:31
  • 1
    I was commenting on your solution only. Your solution works as expected. I suggested using the "mark object" feature of Android Studio in combination with your solution. It is explained in https://medium.com/androiddevelopers/debugging-in-android-studio-dfbbf8a8d03c. – Shubham AgaRwal Feb 21 '23 at 05:27
  • That's helpful. Thanks for sharing. – Red M Feb 21 '23 at 14:09
5

sometimes there will be problem in auto generated binding files, if so it will be solved after invalidate cache and restart ide. sometimes the warning/error show but the project and complied without errors. so no need to worry about that. for next time post the code as code not screen shots.

vignesh
  • 492
  • 3
  • 9