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

Android

Add image via xml: error

Hello,

I've been trying to add an image to my program via xml (since I can't do it via layout since I'm having rendering problems) and I keep getting an error. Here is the code that I used:

android:src="@drawable/main_title.png"

And I have the image in the proper folder, so now I'm stuck.

Any help would be greatly appreciated.

what error are you getting??

2 Answers

Simon Coates
Simon Coates
28,694 Points

i just created an image inside android studio\drawables. Image was called plonk.bmp. Was able to access it with android:background="@drawable/plonk". So maybe try without the file extension.

Thanks for the response. I tried and got this response: Error:(20, 22) No resource found that matches the given name (at 'src' with value '@drawable/main_title').

Simon Coates
Simon Coates
28,694 Points

sorry i couldn't help. My images (.bmp, .png) are definitely in the res\drawable folder and I was able to use src or background attributes to access them without the extension.

@Chris Vaughan, this is the error: "Error:(20, 22) No resource type specified (at 'src' with value '@drawable\main_title.png')."