Android – getIdentifier always returns 0 (library +application)

I have Android project (com.appocaliptic.quizknife.app) which uses Android library (com.appocaliptic.quizknife.core).

What I am trying to do, is to get resource id of the picture which is the library. Path to the image is: res/drawable-xhdpi/fr_200_133.png

  • Expand Search View to use entire Action Bar (hide other things)
  • Does Android ProximityAlert or Geofence drain more battery when the phone is closer to a monitored location?
  • How to make a class with nested objects Parcelable
  • How to make a replacement over the webs loaded in a Webview
  • Why is this simple service not starting?
  • Android Back Button and Progress Dialog
  • However, all tries with getIdentifier result 0. Where is the problem?

    resId = getResources().getIdentifier("fr_200_133", "drawable", "com.appocaliptic.quizknife.core");
    resId = getResources().getIdentifier("com.appocaliptic.quizknife.core:drawable/"+"fr_200_133", null, null);
    resId = getResources().getIdentifier("drawable/fr_200_133", null, "com.appocaliptic.quizknife.core");
    

    Edited:

    Ach, and in R.java there is drawable and corensponding attribute.

    Related posts:

    Android differences between signed and unsigned .apk files?
    Error during Sync: timeout when deploying apk to device using maven
    Android: Drawn canvas paint gone if resuming app from notification bar
    Error:Unable to locate adb within SDK in Android Studio
    Facebook login fragment closes application, using Facebook SDK 3.0.1
    How to implement a two-finger double-click in Android?
  • Android TextureView / Drawing / Painting Performance
  • Android takes more time on application start up during first time launch
  • Initiating Video Call
  • Android Server Socket
  • How to send a POST request using volley with string body?
  • How to add Facebook Share button in Android Application
  • 4 Solutions collect form web for “Android – getIdentifier always returns 0 (library +application)”

    You should not be using the library package name. Try this instead:

    resId = getResources().getIdentifier("fr_200_133", "drawable", getPackageName());
    

    (or getContext().getPackageName() if this is executing in a view).

    I faced the same problem: “getIdentifier result 0” and i solved it by removing image extension (*.jpg, *.jpeg,… etc) to be match the name as it in R.java file

    I was getting the same error and the only thing that worked was going about it in a different way:

    resourceId = R.drawable.class.getField("fr_200_133").getInt(null);
    

    I had a similar issue. I could resolve it similar to what Hussam Otri mentions. For example:

    //This doesn't work
    context.getResources().getIdentifier("audio_1.mp3", "raw", this.getPackageName()); 
    
    //This works (strip off the file extension)
    context.getResources().getIdentifier("audio_1", "raw", this.getPackageName());
    
    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.