Hi All,
I'm a new developer and this is my first android app. I'm developing using Eclipse Juno and I'm trying to use the admob ads for my app but the ad is not working despite all that I've tried.
This is my first time using admob this are the codes in my activity related to the ad;
public class MainActivity extends Activity {
....
....
protected void onCreate(Bundle savedInstanceState) {
........
// Create the adView.
adView = new AdView(this);
adView.setAdSize(AdSize.SMART_BANNER);
///I've inserted the test ad id (abc)read from logcat after launching in the emulator
adView.setAdUnitId("abc");
// Add the AdView to the view hierarchy. The view will have no size
// until the ad is loaded. This code assumes you have a LinearLayout with
// attribute android:id="@+id/linear_layout" in your activity_main.xml.
LinearLayout layout = (LinearLayout) findViewById(R.id.ForViewLin);
layout.addView(adView);
// Create an ad request. Check logcat output for the hashed device ID to
// get test ads on a physical device.
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("abc")
.build();
// Start loading the ad in the background.
adView.loadAd(adRequest);
The following is my XML codes
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
.......
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:orientation="horizontal" >
<com.google.ads.AdView
android:id="@+id/ForViewAd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
</RelativeLayout>
The logcat readouts upon running the app on the emulator is both strange and confusing
10-01 11:45:34.674: D/OpenGLRenderer(1370): TextureCache::flush: target size: 678912
10-01 11:45:34.674: D/OpenGLRenderer(1370): TextureCache::callback: name, removed size, mSize = 22, 1048576, 82944
10-01 11:45:38.678: W/GooglePlayServicesUtil(1370): Google Play services is missing.
10-01 11:45:38.678: I/Ads(1370): Starting ad request.
10-01 11:45:38.678: I/Ads(1370): Use AdRequest.Builder.addTestDevice("abc") to get test ads on this device.
10-01 11:45:38.754: W/Ads(1370): Not enough space to show ad. Needs 360x50 dp, but only has 340x519 dp.
10-01 11:45:38.754: W/Ads(1370): Not enough space to show ad. Needs 360x50 dp, but only has 340x499 dp.
10-01 11:45:38.790: W/EGL_emulation(1370): eglSurfaceAttrib not implemented
10-01 11:45:38.826: D/OpenGLRenderer(1370): TextureCache::get: create texture(0xb90f98e0): name, size, mSize = 27, 1048576, 1131520
10-01 11:45:38.894: W/Ads(1370): Not enough space to show ad. Needs 360x50 dp, but only has 340x519 dp.
10-01 11:45:38.894: W/Ads(1370): Not enough space to show ad. Needs 360x50 dp, but only has 340x499 dp.
10-01 11:45:38.946: W/Ads(1370): Invalid unknown request error: [Cannot determine request type. Is your ad unit id correct?]
10-01 11:45:38.946: W/Ads(1370): There was a problem getting an ad response. ErrorCode: 1
10-01 11:45:38.946: W/Ads(1370): Failed to load ad: 1
As you can see, there are at least 3 errors shown from the logcat. Firstly, it says the google play services are missing, but I've already imported it to the project and place the necessary code in the manifest. I can see it at the android private libraries folder (but not in the libs folder).
There's also the error that says not enough space but I've set the relativelayout right and left padding as 0sp. so there should be enough space widthwise?
Finally, the error code 1, or "Invalid unknown request error"?. I'm not sure what that means?
Other than the logcat and the fact that the ads are not showing anywhere on the activity, the app ran as per normal without problems. I've tried running the app on a bigger emulator (e.g. nexus 10) but the same logcat shows.
Can someone please tell me what I did wrong?
The following are the logcat after what was suggested
09-29 17:31:47.290: D/jdwp(1025): Got wake-up signal, bailing out of select
09-29 17:31:47.290: D/dalvikvm(1025): Debugger has detached; object registry had 1 entries
09-29 17:31:47.302: W/GooglePlayServicesUtil(968): Google Play services is missing.
09-29 17:31:47.302: I/AndroidRuntime(1025): NOTE: attach of thread 'Binder_3' failed
09-29 17:31:47.318: I/Ads(968): Starting ad request.
09-29 17:31:47.318: I/Ads(968): Use AdRequest.Builder.addTestDevice("XXXXXX") to get test ads on this device.
09-29 17:31:47.418: W/Ads(968): Not enough space to show ad. Needs 360x50 dp, but only has 340x519 dp.
09-29 17:31:47.422: W/Ads(968): Not enough space to show ad. Needs 360x50 dp, but only has 340x499 dp.
09-29 17:31:47.446: W/EGL_emulation(968): eglSurfaceAttrib not implemented
09-29 17:31:47.454: D/OpenGLRenderer(968): TextureCache::get: create texture(0xb820e8e0): name, size, mSize = 38, 1048576, 1131520
09-29 17:31:47.526: I/ActivityManager(324): Displayed com.example.testapp/com.example.testapp.MainActivity: +249ms
09-29 17:31:47.530: W/Ads(968): Not enough space to show ad. Needs 360x50 dp, but only has 340x519 dp.
09-29 17:31:47.530: W/Ads(968): Not enough space to show ad. Needs 360x50 dp, but only has 340x499 dp.
09-29 17:31:47.606: W/Ads(968): Invalid unknown request error: [Cannot determine request type. Is your ad unit id correct?]
09-29 17:31:47.610: W/Ads(968): There was a problem getting an ad response. ErrorCode: 1
09-29 17:31:47.610: W/Ads(968): Failed to load ad: 1
09-29 17:31:47.622: D/dalvikvm(968): GC_CONCURRENT freed 256K, 4% free 11580K/11975K, paused 1ms+1ms, total 15ms
09-29 17:31:47.622: D/webviewglue(968): nativeDestroy view: 0xb85bfb60
Please help. I've been stuck at this for the past week already with no more ideas..
Thanks.