1

I am working with a library as a JAR where i have added strings and sending the context of main Application to fetch string to register GCM.

This is my method in the JAR file:-

void registerGCM(Context context){

GCMLibrary.register(context, context.getString(R.string.c2dm_sender));

}

I have declared c2dm_sender in library and in my Application in Strings.

But i am getting this error:

android.content.res.Resources$NotFoundException

I have seen this Using R resources from an android jar file as a reference but not getting it resolved.

I am looking for the solution that R file of my Application is used and c2dm_sender to be used from there.

Community
  • 1
  • 1
Prabhjot Singh
  • 526
  • 1
  • 3
  • 17
  • 1
    Please check that you are importing the correct R file. My Android environment has the habit of importing a default R file. – Eric Tobias Sep 02 '13 at 11:11
  • @EricTobias: i have imported a correct R file. If i use the library as a library project everything works well. but as i create its JAR it does not picks resource – Prabhjot Singh Sep 02 '13 at 11:13
  • 1
    Are you positive that the JAR contains the resource? If so, then I'd say this is a classical problem of correctly referencing the location of the file. Please read http://stackoverflow.com/questions/1900154/classpath-resource-within-jar for more advice on the matter. – Eric Tobias Sep 02 '13 at 11:24
  • Yes i am sure JAR contains a resource.I have another project where this is working – Prabhjot Singh Sep 02 '13 at 11:28
  • 1
    Perfect. Than all you need to do is correctly determining the location of the resource. The link I provided should help. – Eric Tobias Sep 02 '13 at 11:43

1 Answers1

1

you can try this code for that......

context.getResources().getString(R.string.c2dm_sender);
Piyush
  • 18,895
  • 5
  • 32
  • 63
Shivang Trivedi
  • 2,182
  • 1
  • 20
  • 26