Getting Resource id of assets folder files get error Android.Content.Res.Resources+NotFoundException

mirkarammirkaram Member ✭✭

i am using
Resources.GetIdentifier("my_fileName","Asstes",My_Pakage_Name);
above line of code,
it give error;

Android.Content.Res.Resources+NotFoundException: Resource ID #0x0

my_fileName name has Build Action to "AndroidAsset" in Assets Folder

System.IO.Stream st =Resources.Assets.Open("sounds");
while above line work file but i need ID of mp3 file for media player

Resource id can can get from Java.IO.File , in this case c# stream not cast to java stream in one step, need more lines to do,

So, i need solution for 'NotFoundException' if someone know please answer

Answers

  • RonNYCRonNYC Member ✭✭✭

    I have had Resource.ID not found errors. What was suggested (on this and other forums) was the save and quit VS, then delete the bin and obj folders along with the ResourceDesigner.cs file in the Resources folder. Restart VS and rebuild. That has worked for me.

  • yelinzhyelinzh Member, Xamarin Team Xamurai
    edited March 14

    Try to use the following code

    //Resources.GetIdentifier("my_fileName","Asstes",My_Pakage_Name);
    var resourceId = (int)typeof(Resource.Drawable).GetField("").GetValue(null);
    
  • mirkarammirkaram Member ✭✭

    @yelinzh i put in GetField("myfile") then GetField("Assets_Folder_Name") ,but dont work each nullpointerreference Exception error occured,
    Actually i am trying to read audio files from Asset folder not Drawable.

  • mirkarammirkaram Member ✭✭

    @RonNYC I followed your description but won't work, each time getting id 0 on which FileNotFoundException occured

  • yelinzhyelinzh Member, Xamarin Team Xamurai

    This exception is thrown by the resource APIs when a requested resource can not be found.
    Could you post detailed information of Exception?

  • mirkarammirkaram Member ✭✭

    @yelinzh Android.Content.Res.Resources+NotFoundException: Resource ID #0x0 thrown, because of id returned each time 0 ,I changed file name and folder as well .

    Resources.GetIdentifier("my_fileName","Asstes",My_Pakage_Name); the fault is in GetIdentifier(...).
    i change 2nd parameter to drawable and 1st to my_image.png , but again id return 0
    i think problem is in Method parameters, may be some thing is missing somewhere.

  • yelinzhyelinzh Member, Xamarin Team Xamurai

    Change 'Asstes' to 'Assets'.

Sign In or Register to comment.