Kotlin: Set Image SRC | Sololearn: Learn to code for FREE!


Kotlin: Set Image SRC

Hello. So I am trying to set the source of an ImageButton (Android Studio) using Kotlin. I looked it up, and found I should just use setImageResource(image) However, I get the error: Unresolved Reference: setImageResource How can I fix it? Thanks!

8/29/2018 8:25:18 PM

Paul Grasser

5 Answers

New Answer


setImageResource is a method of ImageButton class then you have to call it on that object type... You did it?


Yes. val btn = imgbtn as ImageButton btn.setImageResource("@drawable/image") This gives me an error (I did import ImageButton


Hmmm... Dont knowing much kotlin system, i can only think that something in configuration is wrong... This happen with other android components?


KrOW no.


Paul Grasser Its very hard figure out what is the problem.... I think that something go bad with environment (android studio or gradle)... Try to clear cache of AS and of Gradle and rebuild all (search on google)