is it possible to use ressources like strings that are defined in library projects in the application-projects? if so, how? because i cant seem to resolve the strings i would like to resolve like this:
String title = "sample";
int id = ressources.getIdentifier(title, "string", "com.package");
gives me this exception
WARN/ResourceType(278): No package identifier when getting value for resource number 0x00000000 WARN/System.err(278): android.content.res.Resources$NotFoundException: String resource ID #0x0
the string ("sample") i am looking for is definitely in this package provided in the strings.xml of the library project. i can even see it in the R.java
In your project code, import the R class:
import com.application.libraryproject.R
Then you can reference any string or other xml-defined resource like this:
String mystring = getString(R.string.app_name);
or similar.
Yes, define the resources in your library project like normal. Then reference them in the project importing the library by prepending the R class with the package name in the AndroidManifest.xml of the library.
So it looks like
is returning
0
, meaning it can't find the specified resource. The subsequent call toressources.getIdentifer()
causes the exception, since0
is not a valid resource id.Here are some debug/alternative ideas:
You've probably already done this a dozen times, but it doesn't hurt mentioning: first recheck spelling of everything:
uses-library
element theAndroidManifest.xml
,title
) or is it specific to that type of resource(strings)? Can you access the resources of another library?Android - Is it possible to create a custom library to use across several applications?
Code
Code
Android, getting resource ID from string?
http://daniel-codes.blogspot.com/2009/12/dynamically-retrieving-resources-in.html
I had a similar issue and I solved it with the
getPackageName()
method within the Project Library.In your case, it should be: