Android won't recognize image in resource folder - android

I added some image file to my android project. When I try reference the image in my Layout (in the ImageView object), the render `Layout does not recognize the image.
Screenshot:
I copied and pasted the images directly into Android Studio. I tried rebuilding and Gradle sync.
Not sure why it is not recognizing the image.

Change your image resource first digit integer to character.
01d - do not use
d01 - use it.

For Android image resources, the name of the file of the resource becomes a Java field name of the same name within the R class that contains all resources. Therefore, the name of the file itself (minus the extension) must also be a valid Java identifier. In your case, your image resource files start with a number, and those are not valid Java field names.

Related

Could not select images from drawable folder

I am trying to add an image slide on my android app.
When I try to add the source for the image, from drawable folder, I can't select the iamges.
Here, a little screenshot to understand better the problem:
Screen
What can I do to solve it?
Thank you for your answer.
the naming convention shouldn't be a number. declare it in small letters, like this -> image_one ......e.tc.
You should use PNG or WEBP images as your drawables.
As you may already know variable names should not start with a number. So in your case using a number as your image name forces the compiler to generate a variable named as your drawable name which cannot be accepted in programming, hence the constant R.drawable.1 does not get generated. Try renaming your drawable to an alphabetical equivalent.

How in delphi can i get a drawable resource ID?

in Delphi, I add image resources to the project (via project > resources and Images), however i need for one java function to give a resource ID in the application's package of the drawable to use. Is it possible to retrieve a resource ID (integer) from my delphi resource file or name ?
If not, how in delphi we can add a custom resource image and retrieve it's resource ID ?
Getting a Resource ID
To retrieve the resource ID of a resource:
id := TAndroidHelper.GetResourceID('my_image', 'drawable');
If you are using an older version of Delphi you may need to use the alternate, older approach:
id := TAndroidHelper.Context.getResources.getIdentifier(StringToJString('my_image'), StringToJString('drawable'), TAndroidHelper.Context.getPackageName);
The shorter, more recent (and convenient) GetResourceID function is merely a wrapper around the earlier longer winded version.
In either case, my_image is the filename (without extension) of the image resource whose ID you need.
The drawable parameter tells the helper that it is a drawable resource ID that you are asking for (as opposed to a string or layout, for example).
Adding Image Resources
To add a custom image resource to your project use the Deployment option of the Project menu in the IDE.
Add your file and set the remote path to a suitable drawable resource folder, e.g.:
res\drawable
res\drawable-xxhdpi
etc
You could put your own scaled versions of the image in each drawable folder for different resolutions. The remote_name must be the same in each case. The specific drawable folder determines the applicable device resolution.
Alternatively you could simply provide one suitably high resolution file. You can place this in either an appropriate high-resolution folder (e.g. drawable-xxxhdpi) or simply in drawable.
Either way, Android will auto-scale the images at runtime for other device resolutions as necessary.
There are lots of Android references on the subject of drawable scaling, alternative versions for different display types etc, including the Android documentation itself of course.
Referencing your comment, there are however no XML files required for adding drawables that are straightforward images.
Additional XML may be necessary for other types of drawable resources, but that will very much depend on the nature of your specific needs.
Bringing It All Together
In the screenshot below the highlighted entry is one that I have added for a PNG image resource. The file is in my project folder so there is no local path (the first column).
The filename is appstore.png and I have configured the deployment to place one copy of that file in the res\drawable' folder of the application when it is deployed (theremote` folder).
This file will rely on auto-scaling for display on different resolutions devices.
To get the resource ID of that resource I then simply write:
id := TAndroidHelper.GetResourceID('appstore', 'drawable');

Vector Asset Studio exception parsing xml

I have an svg file (vector graphics) which opens fine in Internet Explorer, but fails when opening in Vector Asset studio (part of android studio) with:
For input string: 2.85465in Exception while parsing XML file:
I think this is caused by the decimal point, where a comma is expected as the computer used has Dutch settings and "," is expected to be the decimal separator.
Where does Vector asset studio gets it's information for this and can it be changed locally?
With this error in Vector Asset:
Could not generate a preview
Exception while parsing XML file:
Premature end of file.
My provisional solution was:
Before getting the .svg file, I generated a .png with Photoshop CC.
I converted my .png to .svg with a converter
Verify that my .svg can be converted to VectorDrawable. This is to know if the Android Studio Vector Asset will be able to perform the conversion.
And finally, I select the VectorDrawable XML that I generated when I checked and paste a resource into the drawable directory, or I use New-> Vector Asset to generate this resource from my verified .svg.
With check I mean make sure the .svg will be parsed to xml with Vector Asset.
So I observed this error occurs when the image has tiny text and when using the .svg converter is likely to skip it.
SVG files are just text files, you can open them in any text editor (like notepad) and change their content as you like.
Try removeing the in or replace it by px. Asset Studio doesn't seem to work with any other size declaration than px.
There was a conversation on google groups, I think, that I recently read. Took the solution from there. Will add the link if I find it again.
// edit: found it: https://code.google.com/p/android/issues/detail?id=189654

Android drawables are not recognized by AndroidStudio if I use dpi subfolders

I have just started the Treehouse Android development course, I have also asked this question on their forums without any luck.
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.
I have created the ImageView for a 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.
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
main_title.png
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.
The only solution I have found is to just copy one version fo the images to the main drawables folder, and deleting all of the subfolders, if I don't delte them then it also doesn't work...
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 has me totally lost!
So, in case anyone wonders, I solved it following both Cris and Rob advices. I installed appcompat v7 and put my img resources (png,jpd, etc) directly inside my drawable folder. Then I created a folder for each dpi resolution inside the res folder, NOT inside the drawable folder.
I use eclipse but i think its pretty much the same, you should have you various drawable folders, then you have to include the R (res folder)
import com.example.project.R;
and then call them by reference
R.drawables.main_title
Note you dont need to specify which drawable folder , adroid does that for you.
Also if you are getting unresolved errors with R then you may need to have the appcompatv7 library inlcuded in your project.

Image in android not getting added to #drawable/

Hello I am developing an android application in which for a ListView I have to added an image to drawable folder but when I am adding it is giving the error.
This is the folders hierarchy of my project
This is the image I wanna add arrow.png
This is the error
[2013-04-03 20:57:37 - FileSharing] res/drawable/arrow.png: Invalid file name: must contain only [a-z0-9_.]
I have changes the file name 10 times according to the conventions but still the error is not going
Well i think you must not put the image file in drawable folder.
you must chose these folder for putting images for your application
If you didn't see these folder create these folder inside res .
Then clean and rebuild your project .Hope this would help you
Also Keep an eye one the name of images must contain only [a-z0-9_.]
I think the default choice is drawable-mdpi folder
Refer this
Clean your project and build again.
Sometimes eclipse behaves wierd.

Categories

Resources