Forum Xamarin Xamarin.Android

Resource: GetIdentifier returns 0, but the resource is there!

I am absolutely baffled by this one. If someone could provide some insight, please please do.

I am developing a Xamarin Android app. I have an image in my "drawable" folder. It happens to be called "typingleft0.png", in case you care. When I look at the Resource.designer.cs file, Visual Studio has correctly generated a resource ID and placed it in that file. Here is the line from Resource.designer.cs:

// aapt resource value: 0x7f02017e
public const int typingleft0 = 2130837886;

When I type code, Visual Studio recognizes that the resource exists - it shows up in autocomplete when I type something like "Resource.Drawable.typ.......". You know what I mean.

But then, there is a certain point in my code where apparently the resource is like a ghost. At a point in my code, I have the string form of the Resource, and I need to get the integer resource ID, so I do so like so:

int resourceID = this.Resources.GetIdentifier("typingleft0", "drawable", this.PackageName);

The variable resourceID is 0. It's like the resource doesn't event exist. When I physically set the resourceID variable to be the same value as typingleft0 (in Resource.designer.cs), the image does not show up in the UI. It is just blank.

Any ideas what could be going on?

Tagged:

Answers

  • LeonLuLeonLu Member, Xamarin Team Xamurai
    edited September 2019

    First of all, If you get the resourceID is 0, It means that cannot found this resource.
    I add a png in the drawable folder, If the name is the same as yours, I got the result is 0.

    But I change the name of png to typingleft , then build my solution, I can get the result like following screenshot.

    Note: all of the name format shoud be the lower case

Sign In or Register to comment.