Skip to content Skip to sidebar Skip to footer

Admob Banner Ad Declaration In Class Giving Errors In Android

In My android game I'm declared admob banner ad in class instead of layout. I had used the following code in onSetContentView: protected void onSetContentView() { final Fr

Solution 1:

I suppose you're using a build target of 19. Your code will compile but will crash on devices/emulators running on android < Api Level 19 because,

the FrameLayout.LayoutParams(FrameLayout.LayoutParams source) constructor is available from API 19. You should cast to the older target API 1 FrameLayout.LayoutParams (ViewGroup.MarginLayoutParams source). Modify your code as follows:

final FrameLayout.LayoutParamsframeLayoutLayoutParams=
               ((ViewGroup.MarginLayoutParams) (newFrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT,
                                             FrameLayout.LayoutParams.FILL_PARENT)));

 final FrameLayout.LayoutParamsadViewLayoutParams=
               ((ViewGroup.MarginLayoutParams) (newFrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
                                             FrameLayout.LayoutParams.WRAP_CONTENT,
                                             Gravity.CENTER_HORIZONTAL|Gravity.BOTTOM)));

Solution 2:

This problem is not caused by admob as is mentioned in your logcat output.

It says FrameLayout.LayoutParams is not a method. Wherever you have: FrameLayout.LayoutParams replace it with ViewGroup.LayoutParams and it should solve your problem.

Post a Comment for "Admob Banner Ad Declaration In Class Giving Errors In Android"