question

vintral avatar image
vintral asked

Can't load an ad because layout parameters are blank

I'm currently working on creating ANE(AIR Native Extension) to incorporate Amazon Ads into our AIR applications. I'm trying to create and retrieve an ad currently and running into a weird issue. [b]Code[/b] Display display = cnt.getActivity().getWindowManager().getDefaultDisplay(); Point size = new Point(); display.getSize(size); cnt.width = size.x; cnt.height = size.y; Log.i("AdControl", "Display Dimensions: " + cnt.width + "x" + cnt.height); AdSize adSize = new AdSize(cnt.width, 100); Log.d("AdControl", "adSize: " + adSize.getWidth() + "x" + adSize.getHeight()); AdLayout adView = new AdLayout(cnt.getActivity(), adSize); adView.setListener(cnt); Log.d("AdControl", "adView with custom size: " + adView.getWidth() + "x" + adView.getHeight()); adView = new AdLayout(cnt.getActivity(), AdSize.SIZE_728x90); Log.d("AdControl", "adView with AdSize.SIZE_728x90: " + adView.getWidth() + "x" + adView.getHeight()); adView.loadAd(new AdTargetingOptions()); Log.d("AdControl", "adView after loadAd: " + adView.getWidth() + "x" + adView.getHeight()); [b]Logged Output[/b] I/AdControl(10424): Display Dimensions: 768x976 D/AdControl(10424): adSize: 768x100 D/AdControl(10424): adView with custom size: 0x0 D/AdControl(10424): adView with AdSize.SIZE_728x90: 0x0 E/AmazonMobileAds AdLayout(10424): Can't load an ad because layout parameters are blank. Use setLayoutParams() to specify dimensions for this AdLayout. D/AmazonMobileAds AdController(10424): adFailed D/AdControl(10424): adView after loadAd: 0x0 So why is the ad size set to 0x0. And how do I fix "Can't load an ad because layout parameters are blank. Use setLayoutParams() to specify dimensions for this AdLayout"? I don't see any accessible setLayoutParams method to call. I can create and compile the test Android Projects with the application, but I can't seem to create an ad when attempting to create an ANE to do so.[b][/b][b][/b] Vintral
mobile ads
10 |5000 characters needed characters left characters exceeded

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

Sujoy@Amazon avatar image
Sujoy@Amazon answered
Hi Vintral, Thank you for your post. The issue you are facing because you have not set width and height of the AdLayout instance which is basically a FrameLayout. Passing adSize with the AdLayout constructor does not set the width and height of the layout. You have to set explicitly. From xml we do it this way, Pragmatically, you can do this way. LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); adView.setLayoutParams(lp);
10 |5000 characters needed characters left characters exceeded

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

Bipin@Amazon avatar image
Bipin@Amazon answered
wrote a quick lines with respect your code your error in logcat : E/AmazonMobileAds AdLayout(10424): Can't load an ad because layout parameters are blank. Use setLayoutParams() to specify dimensions for this AdLayout. so adview can be set with layout parameters example: AdLayout adView = new AdLayout(this, AdSize.SIZE_728x90); float scale = this.getApplicationContext().getResources().getDisplayMetrics().density; adView.setLayoutParams(new FrameLayout.LayoutParams((int) (728 * scale),(int) (90 * scale), Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL)); adView.setListener(this); adView.loadAd(new AdTargetingOptions());
10 |5000 characters needed characters left characters exceeded

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

vintral avatar image
vintral answered
Sorry, for not replying sooner. But that lead me on the path I needed to fix things. I guess I was a bit stupid and didn't notice that section on layout params in the one sample either. Just noticed that today while tweaking some things. So thanks for the assistance.
10 |5000 characters needed characters left characters exceeded

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