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!
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
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.