Tag Archives: admob.adsense

Errors and Issues Found While Adding AdMob for Android

On my to do list for a while was to add advertisements to my application, CountView. I’m not really interested in making a profit in any way but I wanted to see how hard it was to do and if you could expect any kind of profit at all. If I’m ever going to make a career of this app and custom development career then it’s best to
start small and work up from there.

Given how common ad platforms are I was expecting that adding them to my app was going to be very straight forward. And in some ways it was. The first choice was between AdSense and AdMob, both provided by Google. Google makes it quite clear that they believe AdMob is the platform of choice for Android apps and apps in general. There’s┬ádefinitely nothing stopping you using AdSense and importing it into a web container but I have to agree that the concept behind AdMob makes sense.

AdMob recently released a new version 4.3.1 that I think came out in October 2011. My first issue was that you needed at least Android 3.2 (the tablet version) to compile it against and for some reason that refused to deploy to my Nexus One running 2.3.3 even though it was supposed to be backward compatible to Android 1.5. I got round most of this by installing the Ice Cream Sandwich Emulator which seemed a lot better than the earlier versions that I had use previously. The even better fix for this was that I bought a Galaxy Nexus. All problems solved!

Then the real problems started. I deployed it and the ad just refused to show. No errors. It said that an ad was being received and then nothing. Added some house ads and still nothing. Added my device multiple ways as a test device and still no luck. Had me stumped for ages. Eventually I found the following errors:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.fozziewossie.android/com.fozziewossie.android.CountViewActivity}: java.lang.ClassCastException: com.google.ads.AdView cannot be cast to android.widget.TextView

Caused by: java.lang.ClassCastException: com.google.ads.AdView cannot be cast to android.widget.TextView

And I was like, what the? All I was doing at that line was:

TextView countTextView = (TextView) findViewById(R.id.CountField);

That made no sense at all to me. I did some extensive Googling and none of it seemed to help. Eventually I just did my standard response when things refused to work and just fecked around.

My solution. Wrap the com.google.ads.AdView component in the XML in a Linear Layout and move it to the top of the application. Why that fixes it I have no idea. I’m results driven, it works!

The new version of CountView is being released tonight and includes one other change to have the background colour default to black with white text. It’s much more sophisticated.