Closed GoogleCodeExporter closed 8 years ago
Hi,
I can see where the NPE is occurring and will add a check around it, but this
seems indicative of a race condition. Could you attach the adapter you are
using? Or, if you're not comfortable with it being public, could you email it
to me?
- Justin
Original comment by jpin...@google.com
on 20 Sep 2010 at 5:09
Original comment by jpin...@google.com
on 20 Sep 2010 at 5:09
Hi Justin,
I could very well be coding my adapter incorrectly as I believe the instructions in the wiki for custom adapters is out of date. I am definitely not seeing the correct behavior at this time: I will see ads replacing themselves very quickly as if threads had stalled and then suddenly awoken possible due to an activity pause after orientation changes. Here is the relevant portions of my source code for an adapter handling requests for JumpTap. I appreciate any help.
public void adWhirlJumpTap() {
try {
final AdWhirlLayout adWhirlLayout = (AdWhirlLayout)((LinearLayout)findViewById(R.id.adWhirlAd)).getChildAt(0);
final User loggedInUser = MocoApplication.getLoggedInUser();
synchronized (jtAdWidgetSettingsLock) {
if (jtAdWidgetSettings == null) {
jtAdWidgetSettings = JtAdWidgetSettingsFactory.createWidgetSettings();
jtAdWidgetSettings.setPublisherId(getString(R.string.jumptap_publisher_id));
jtAdWidgetSettings.setSiteId(getString(R.string.jumptap_site_id));
jtAdWidgetSettings.setSpotId(getString(R.string.jumptap_spot_id_banner));
jtAdWidgetSettings.setShouldSendLocation(false);
try {
PackageManager pm = getApplicationContext().getPackageManager();
PackageInfo pi = pm.getPackageInfo(getApplicationContext().getPackageName(), 0);
// Version
jtAdWidgetSettings.setApplicationId(android.os.Build.ID);
jtAdWidgetSettings.setApplicationVersion(pi.versionName);
} catch (Throwable t) {}
}
// set logged in user particulars
if (loggedInUser != null) {
jtAdWidgetSettings.setAge(Integer.toString(loggedInUser.getAge()));
jtAdWidgetSettings.setAdultContentType(loggedInUser.getAge() > 17 ?
JtAdWidgetSettings.AdultContent.ALLOWED : JtAdWidgetSettings.AdultContent.NOT_ALLOWED);
jtAdWidgetSettings.setGender(loggedInUser.isMale() ? "m" : "f");
}
}
JtAdView adView = new JtAdView(this, jtAdWidgetSettings);
adView.setAdViewListener(new JtAdViewListener() {
@Override
public void onAdError(JtAdView adView, int widgetId, int errorCode) {
Log.i(MocoActivity.class.getSimpleName(),"onAdError: "+errorCode);
onCustomAdFailure(adWhirlLayout);
}
@Override
public void onFocusChange(JtAdView view, int arg1, boolean arg2) {
Log.i(MocoActivity.class.getSimpleName(),"onFocusChange");
}
@Override
public void onInterstitialDismissed(JtAdView view, int errorCode) {
Log.i(MocoActivity.class.getSimpleName(),"errorCode: "+errorCode);
}
@Override
public void onNewAd(JtAdView adView, int arg1, String adInfo) {
Log.i(MocoActivity.class.getSimpleName(),"onNewAd: "+adInfo);
onCustomAdSuccess(adWhirlLayout);
}
@Override
public void onNoAdFound(JtAdView adView, int errorCode) {
Log.i(MocoActivity.class.getSimpleName(),"onNoAdFound: "+errorCode);
onCustomAdFailure(adWhirlLayout);
}
});
adWhirlLayout.removeAllViews();
adWhirlLayout.addView(adView,
new android.widget.RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
adWhirlLayout.invalidate();
} catch (Throwable t) {
Log.e(this.getClass().getSimpleName(),"Error inflating inmobi ad",t);
}
}
private void onCustomAdFailure(AdWhirlLayout adWhirlLayout) {
//adWhirlLayout.rotateThreadedNow();
//adWhirlLayout.removeView(adView);
try {
adWhirlLayout.rollover();
} catch (Exception e) {
e.printStackTrace();
}
}
private void onCustomAdSuccess(AdWhirlLayout adWhirlLayout) {
try {
adWhirlLayout.adWhirlManager.resetRollover();
adWhirlLayout.rotateThreadedDelayed();
} catch (Exception e) {
e.printStackTrace();
}
}
Original comment by keithwri...@gmail.com
on 20 Sep 2010 at 5:16
Hmm. Well... I think it went something like this:
Your custom event gets triggered.
It fails.
AdMob gets triggered.
It succeeds.
Your custom event gets triggered.
It fails.
AdMob gets triggered.
It fails.
Rollover now returns null.
countImpression() from the first AdMob call now throws a NPE.
This would be consistent with the "flickering" ads it sounds like you're
seeing.
On a side note, you should use "adWhirlLayout.handler.post(new
ViewAdRunnable(adWhirlLayout, adView));" instead of removing and adding the ad
view yourself. That way you'll get AdWhirl stats for it.
I don't see anything in this code that would cause the NPE though... do you
have other custom events that you use? Or maybe the log output right before the
exception?
Original comment by jpin...@google.com
on 20 Sep 2010 at 6:22
I believe that I did have an error in my getLoggedInUser call that could have
been causing the issue. Fixing that combined with using
adWhirlLayout.handler.post(new AdWhirlLayout.ViewAdRunnable(adWhirlLayout,
adView)); seems to have resolved the issue. Although I am seeing out of memory
exceptions when I do several orientation changes in a row. I will confirm and
if so file another issue. Thanks!
Original comment by keithwri...@gmail.com
on 20 Sep 2010 at 6:41
Yeah, that could do it, especially since that block is synchronized. I added in
the NPE checks for version 2.5.5 - let me know if you have more problems around
this.
Original comment by jpin...@google.com
on 20 Sep 2010 at 9:07
Original issue reported on code.google.com by
keithwri...@gmail.com
on 20 Sep 2010 at 1:45