0
votes

When I was having the project main_app, I was able to access the resources with-

int resId = getResources().getIdentifier("xml/" + rule_file, "string", "com.main_app.main");

Now, my project main_app is the library project for the project test_app.

But when I run the test_app I always get the exception at -

int resId = getResources().getIdentifier("xml/" + rule_file, "string", "com.main_app.main"); //Line 5456

The error log -

03-04 15:53:50.158: E/AndroidRuntime(29898): Caused by:
android.content.res.Resources$NotFoundException: Resource ID #0x0
03-04 15:53:50.158: E/AndroidRuntime(29898):  at
android.content.res.Resources.getValue(Resources.java:1017) 03-04
15:53:50.158: E/AndroidRuntime(29898):    at
android.content.res.Resources.loadXmlResourceParser(Resources.java:2102)
03-04 15:53:50.158: E/AndroidRuntime(29898):  at
android.content.res.Resources.getXml(Resources.java:905) 03-04
15:53:50.158: E/AndroidRuntime(29898):    at
com.main_app.main.ClainFragment$23.run(ClainFragment.java:5456)
1
are they both project located at same location ?Lucifer
@Kedarnath - yes same workspace.My God
instead of hardcode the package name use getPackageName()Blackbelt
@blackbelt - this was the real way..You saved the day. Thanks.My God

1 Answers

0
votes

As @blackbelt commented out,

The package name should be the package of project test_app that is the one we define in the manifest file of project test_app like -

 package="com.test_app.main"

So hardcoding with the line like -

int resId = getResources().getIdentifier("xml/" + rule_file, "string", "com.main_app.main"); 

was wrong.

Changed to -

int resId = getResources().getIdentifier("xml/" + rule_file, "string", getActivity().getPackageName());

It worked!