question

Carlos Botero avatar image
Carlos Botero asked

NullPointerException from adView, trying to implement Amazon ads in Android Studio

Hi. I am trying to include Amazon ad banners in my Android App. I am following the

QuickStart Guide (https://developer.amazon.com/docs/mobile-ads/mb-quick-start.html).

After setting the App Key, I initialize the adView variable:

this.adView = (AdLayout) findViewById(R.id.adview);

but the variable adView turns red with the warning: Cannot resolve symbol

So, guessing that the type of this adView variable is: com.amazon.device.ads.AdLayout,

I implement instead:

com.amazon.device.ads.AdLayout adView = (AdLayout) findViewById(R.id.adview);
AdTargetingOptions adOptions = new AdTargetingOptions();

But if I run the code, I get: NullPointerException in:

this.adView.loadAd(adOptions);

It seems that they have been correctly instantiated, so what am I missing here?

By the way, they recommend to include the Google Play Services SDK, but the specific Google site doesn't actually specify which libraries we should add. And adding all the Play libraries seems inconvenient. I guess that they implicitly suggest to install the Play library to run Google Mobile Ads (

com.google.android.gms:play-services-ads:15.0.1), right?

Can you point me to a basic Android APP that actually runs Amazon banners, so I can guesstimate what is not working with my own App? Thanks

mobile adsandroidappamazon developer portal
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

Ross@Amazon avatar image
Ross@Amazon answered

All the information you need to get started with Amazon Mobile Ads can be found here: https://developer.amazon.com/public/apis/earn/mobile-ads.

Please refer to the mobile ads sample apps included with the SDK. They are fully functioning demos of all Amazon Mobile Ad types. These samples should help you better understand how Amazon Mobile Ads are implemented. Code can be copied directly from these projects and modified as needed to quickly place ads in your app. More information regarding these sample apps can be found here: https://developer.amazon.com/public/apis/earn/mobile-ads/docs/sample-apps.

10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.