"Cannot get viewWidth error after first layout"

I cannot fix this error for the life of me. I looked at Google and around, and no solutions worked. My ad seems to work fine on Android 1.5 and 1.6, but above version 2 I get this error.

I placed my ad inside LinearLayout, which is the first scroll arrangement.

<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" android:orientation="vertical" android:background="@drawable/bg_wallpaper" android:layout_width="fill_parent" android:layout_height="wrap_content"> <LinearLayout android:orientation="vertical" android:id="@+id/drillactivity" android:layout_width="fill_parent" android:layout_gravity="bottom" android:layout_height="340dp"> <com.google.ads.AdView android:id="@+id/adView" android:layout_width="wrap_content" android:layout_height="wrap_content" ads:adUnitId="my id goes here" ads:adSize="BANNER" ads:loadAdOnCreate="true"/> 

I do not use any code in my class to declare. I prefer to do this only through xml.

+4
source share
3 answers

I had a similar warning with a black screen. The problem was that the device had two different applications with the same AdMob ID.

I uninstalled the second application (using the same identifier by mistake) and the problem disappeared.

+3
source

Using the following code, I fixed this error.

 <com.google.ads.AdView android:id="@+id/adView" android:layout_width="320dp" android:layout_height="50dp" android:gravity="center" ads:adUnitId="my id goes here" ads:adSize="BANNER" ads:loadAdOnCreate="true"/> 

I have no specific reason for this error; it may not work in every case.

+3
source

Declare a linear / relative layout in xml that you do in your activity. and then set the activity as a listener for adView. For instance:

 googleAdView = new AdView(Activity,AdSize.IAB_BANNER, ADMOB_SITE_ID); googleAdView.setAdListener(Activity); com.google.ads.AdRequest request = new com.google.ads.AdRequest(); this.adMobLayout.removeAllViews(); this.adMobLayout.addView(googleAdView); googleAdView.loadAd(request); 

Here adMobLayout is the layout you specified in the xml layout.

0
source

All Articles