tags:

views:

49

answers:

1

hi

i tried to invoke another activity from my main acitivty which is located in a jar file.

Class clazz = Class.forName(getPackageName() + "." + getActivityName()); startActivity(new Intent(this, clazz));

Im doing it this way because i only know the name of the class. This works fine but unfortunately, all resource files can't be found while loading the activity from the jar file. at the first occurence of loading a res file there is a ResourceNotFoundException:

04-30 11:18:46.944: ERROR/AndroidRuntime(1749): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f040006

any hints for that? thanks!

+1  A: 

Your JAR cannot reference resources.

To be more specific:

  • Your JAR cannot contain resources
  • Your Java code in the JAR cannot use R.layout or R.id or R.drawable or any of the R. constants to refer to resources

You need to have all of your resources in the application that is reusing the JAR, and your JAR's Java code needs to either have resource IDs passed into it (e.g., via method parameters) or use getIdentifier() to find out the resource ID at runtime from a String representation of the name.

CommonsWare
ok thanks a lot for your answer! But is there really no other way do to that? If i cant change the jar file, how should I be able to do your solution?
Roflcoptr
"But is there really no other way do to that?" I am not certain what "that" is. "If i cant change the jar file, how should I be able to do your solution?" Talk to whoever created the JAR and point them to this StackOverflow question. If they did not create the JAR properly, there is nothing you can do, unless you have the source code, in which case you could try fixing it yourself.
CommonsWare
Ok to clarify my answer:Is there no other way to get the application in the jar running than to place the resource files in the application that is calling the application in the jar file.
Roflcoptr
I do not have your JAR file. I can only go by what you have reported here. It would appear that the JAR file needs to be rewritten as I described in my original answer. Contact the author of the JAR, or obtain the source code for that JAR.
CommonsWare