In Need of some help!

walterf25

Expert
Licensed User
Longtime User
Hello all, i'm working on an ads library, the library is able to display fullscreen ads, interstitial ads, video ads etc....

But i need some help figuring something out, In the example i have downloaded from the ads company and which obviously runs in eclipse everything works fine, on the interstitial ads there's a "close" button on the top right side of the ad, the images that are automatically assigned by the sdk to the close button are in the res/drawable folder, when i port the jar file and xml files to use them in Basic4Android everything works fine but for the interstitial ads there's no "close button", i tried copying the two image files to the res/drawable folder in basic4android but i still get this error;

java.lang.NoSuchFieldException: tapit_interstitial_close_button_normal
at java.lang.ClassCache.findFieldByName(ClassCache.java:446)
at java.lang.Class.getField(Class.java:864)
at com.tapit.adview.AdInterstitialBaseView.getResourceIdByName(AdInterstitialBaseView.java:233)
at com.tapit.adview.AdInterstitialView.showInterstitialCloseButton(AdInterstitialView.java:39)
at com.tapit.adview.AdInterstitialView.getInterstitialView(AdInterstitialView.java:30)
at com.tapit.adview.AdActivity.onCreate(AdActivity.java:31)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1660)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1716)
at android.app.ActivityThread.access$1500(ActivityThread.java:124)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:968)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3806)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
No package identifier when getting value for resource number 0x00000000


android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.content.res.Resources.getValue(Resources.java:907)
at android.content.res.Resources.getDrawable(Resources.java:595)
at com.tapit.adview.AdInterstitialView.showInterstitialCloseButton(AdInterstitialView.java:39)
at com.tapit.adview.AdInterstitialView.getInterstitialView(AdInterstitialView.java:30)
at com.tapit.adview.AdActivity.onCreate(AdActivity.java:31)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1660)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1716)
at android.app.ActivityThread.access$1500(ActivityThread.java:124)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:968)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3806)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)

I know the problem is that it doesn't find the interstitial_close_button_normal image, is there a way to add this either to the manifest file, to tell it where to get this image from, i also tried adding it to the R.java file like this
public static final int interstitial_close_button_normal=0x7f020001;
but it doesn't work either.

does anyone here have any idea how to solve this issue?

thanks,
Walter
 

barx

Well-Known Member
Licensed User
Longtime User
OK, 2 things to check

1) did you make the files Read-Only when you copied them over. B4A deletes any alien files, so they need to be flagged Read-Only

2) did you 'Tools', 'Clean Project' in b4a. This must be done each time you add such files so the R.Java file that lists such resources is deleted and re-created including the new additions.
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Hi.

Take a look at this method from my AndroidResources library:

B4X:
/**
 * Get a application resource Drawable by ResourceName.
 *Returns Null if the Drawable is not found.
 */
public static Drawable GetApplicationDrawable(String ResourceName) {
   int resourceId = BA.applicationContext.getResources().getIdentifier(ResourceName, "drawable", BA.packageName);
   if (resourceId == 0) {
      return null;
   } else {
      return BA.applicationContext.getResources().getDrawable(resourceId);
   }
}

Does your library code require a Drawable or the ID of the Drawable resource?

You can get the ID of the Drawable resource like this:

B4X:
int resourceId = BA.applicationContext.getResources().getIdentifier("interstitial_close_button_normal", "drawable", BA.packageName);


If you require a Drawable and not the Drawable resource ID you might as well copy/paste my method into your library, you could even create a new method to get a Drawable resource ID:

B4X:
/**
 * Get a application resource Drawable ID by ResourceName.
 *Returns zero if the Drawable is not found.
 */
public static int GetApplicationDrawableID(String ResourceName) {
   return BA.applicationContext.getResources().getIdentifier(ResourceName, "drawable", BA.packageName);
}

All references to the BA object are static - as long as your library has B4AShared.jar referenced on it's build path it will work.

The complete source code for AndroidResources is attached - you might find it useful.

Martin.
 

Attachments

  • AndroidResources.zip
    1.2 KB · Views: 218
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Thank you Warwound

Thanks for your help Warwound, I actually did what barx suggested and it works fine now, but i will keep in mind your suggestion for other projects.

Thank you guys!

cheers,
Walter
 
Upvote 0
Top