1

I'm currently creating a payment SDK for android, as such I want to send some images from the sdk/library project to the actual application based on different situations. I want the users of the application to use the drawables, but I dont want them to set it manually(i.e get it directly from the SDK's drawable folder), the SDK should automatically choose what image to use based on difference situations.

Currently what I have is a DAO class which when initilized have something like:

case (MASTERCARD):
    this._logo = getResources().getDrawable(R.drawable.mastercard_securecode);

and then in the application I want to be able to fetch that drawable and use it in an ImageView like this:

img.setImageDrawable(DAOObject.getLogo());

However when running this I get

06-15 20:25:18.933: W/dalvikvm(625): VFY: unable to resolve static field 6 (mastercard_securecode) in LPackagePath/R$drawable;

followed by a nullpointer exception as getLogo will return null due to the above error.

Anyone know how to implement this properly so I dont get the above errors and still be able to implement it this way where the application gets the drawable sent dynamically as such?

Any help is much appreciated!

Jacob
  • 3,521
  • 6
  • 26
  • 34
  • Where is setter method in switch case statement? Some what like DAOObject.setLogo() – Venky Jun 19 '12 at 14:26
  • the switch case statement is placed in the DOAObjects constructor, so I just access the local _logo variable directly. – Jacob Jun 19 '12 at 14:32
  • Are you on the latest version of the Android SDK tools? – CommonsWare Jun 19 '12 at 15:28
  • yes.. I'm loading the library project as a jar file in the libs folder of the application. The library project is the one containing the actual ressources and the switch statement. – Jacob Jun 19 '12 at 15:36
  • How do you generate the jar file from library project? Note that the one eclipse generated doesn't contain R.class, it is only used temporarily when Eclipse clean/build you applicatiob project and not suppose to be used as a complete self-contained jar file. – yorkw Jun 19 '12 at 21:37
  • That might be the problem. What is the proper way for exporting the jar file then? I need it to be closed source. Exporting it right clicking on the project then export in eclipse causes errors such as dublicate files (AdnroidManifest.xml) for example, but I assume this is needed? - Secondly I just tired to do import the library project by going to the project properties then Android and importing the library project there, however I still get a null pointer exception (but the "unable to resolve static field" errors are gone) – Jacob Jun 20 '12 at 08:17
  • Please see this link https://stackoverflow.com/a/70844512/12272687 – Mori Jan 25 '22 at 06:58

1 Answers1

1

Okay so I figured this out finally.

The problem really was Context. I needed to pass the context from the application into the SDK and then I could get the images properly by doing

context.getResources().getDrawable(R.drawable.mastercard_securecode);

Secondly I needed to import the jar file in a library project and then import the images in that second library project so that the SDK it self is closed source but I still had the ressources available.

Jacob
  • 3,521
  • 6
  • 26
  • 34