Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Pedro Baumann
12,815 Pointshow to implement @drawables? App doesn't build because it doesn't find the resource
I am styarting with the Choose your own adventure Android App, and I have stumbled uppon something I haven't been able to figure out for a couple of hours.
DATA:
- AndroidStudio v 1.2.2, the course is based on v0.86 I think
- OS / DE: Manjaro Linux, KDE
I have copied the image files inside the drawable folder, each into their specific dpi folder.
Project files won't run on my machine, even though I updated every requisite shown to me by Android Studio
I have created the ImageView for the mail_title.png, and added the src as the full path to the png. When I do that, the image loads into the preview screen, and I can work with it, but If I try to build the app it just says the value of src cannot be a string.
So then I tried to point to it as a resource. On many forums and the android documentation I only found that I should reference it through a "pointer" @drawable/main_title , when I downloaded the projectfiles from the course I saw thats how they did it too.
If I try to rebuild now it gives the following error:
Error:(14, 22) No resource found that matches the given name (at 'src' with value '@drawable/main_title').
Then I tried to create a resource inside strings.xml, I found some autocomplete function that pointed me in "the right direction", of course it did not work!, same error as before. I have tried using absolute paths as well without luck.
I somehow suspect it has something to do with the IDE itself, right now It shows R as "cannot resolve symbol R" in the MAinActivity file. I figured out by reading online that this is due to my drawable not existing problem.
Then I created a refs.xml in values and added
<?xml version="1.0" encoding="utf-8"?> <resources> <drawable name="main_title">main_title.png</drawable> </resources>
I actually tried with and without the extension (png)
After that I clicked on the IDE suggestion to create a drawable folder and it just created a @drawable folder inside of layout....
Basically it says it cannot resolve directory @drawable from activity_main.xml
and also Error:(3, 33) String types not allowed (at 'main_title' with value 'main_title.png'). on the refs.xml file (this happens whether I use the extension (png) or not.
So, as you can see I'm kinda lost... Any help would be appreciated. I'm a python backend developer and I'm pretty comfortable usiong Pycharm (IntelliJ for python), but somehow I feel Android Studio keeps failing me!
Pedro Baumann
12,815 PointsPedro Baumann
12,815 PointsI have kind of solved it, it now shows the images correctly if I don't use the predefined hdpi and so folders and just drag everything into drawable. Any way to solve this?