1

I have been trying to get my advert to show, but it will not show....I just keep getting the below errors, but I am not sure what they mean. I have imported the google-play services correctly.

Any help will be great, thanks!

UPDATE

I have solved it.

The error which was causing it to stop was the 'No enough space', this was due to me using the linear layout. Upon switching to a relative Layout, it worked fine.

Main.java:

package com.example.f;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
//import com.google.android.gms.samples.ads.R;
//import com.google.android.gms.samples.ads.ToastAdListener;


public class MainActivity extends ActionBarActivity {

     private AdView adView;
     //This is the unit ID I get from admob account right?
     private static final String AD_UNIT_ID = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Create an ad.
        adView = new AdView(this);
        adView.setAdSize(AdSize.BANNER);
        adView.setAdUnitId(AD_UNIT_ID);
        LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout);
        layout.addView(adView);

        AdRequest adRequest = new AdRequest.Builder()
        .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
        .addTestDevice("INSERT_YOUR_HASHED_DEVICE_ID_HERE")
        .build();

    // Start loading the ad in the background.
    adView.loadAd(adRequest);  

    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onResume() {
      super.onResume();
      if (adView != null) {
        adView.resume();
      }
    }

    @Override
    public void onPause() {
      if (adView != null) {
        adView.pause();
      }
      super.onPause();
    }

    /** Called before the activity is destroyed. */
    @Override
    public void onDestroy() {
      // Destroy the AdView.
      if (adView != null) {
        adView.destroy();
      }
      super.onDestroy();
    }
}

main.xml file:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/linearLayout"
    android:layout_width="match_parent"
   android:layout_height="wrap_content"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="0dp"
    android:paddingRight="0dp"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.f.MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

    <com.google.android.gms.ads.AdView android:id="@+id/adView"
                           android:layout_width="match_parent"
                           android:layout_height="wrap_content"
                           ads:adSize="BANNER"
                           ads:adUnitId=""

                           />

</LinearLayout>

LogCat:

08-31 17:32:36.309: W/ApplicationPackageManager(8370): getCSCPackageItemText()
08-31 17:32:36.429: D/dalvikvm(8370): DexOpt: --- BEGIN 'ads-1174894372.jar' (bootstrap=0) ---
08-31 17:32:36.439: I/Ads(8370): Starting ad request.
08-31 17:32:36.439: I/Ads(8370): Use AdRequest.Builder.addTestDevice("4F1AF66A4340D91DEDBA62394D3A289B") to get test ads on this device.
08-31 17:32:36.449: I/Ads(8370): Please set theme of AdActivity to @android:style/Theme.Translucent to enable transparent background interstitial ad.
08-31 17:32:36.459: V/WebViewChromium(8370): Binding Chromium to the background looper Looper (main, tid 1) {42d13f70}
08-31 17:32:36.459: I/chromium(8370): [INFO:library_loader_hooks.cc(112)] Chromium logging enabled: level = 0, default verbosity = 0
08-31 17:32:36.459: I/BrowserProcessMain(8370): Initializing chromium process, renderers=0
08-31 17:32:36.469: W/chromium(8370): [WARNING:proxy_service.cc(888)] PAC support disabled because there is no system implementation
08-31 17:32:36.469: W/ApplicationPackageManager(8370): getCSCPackageItemText()
08-31 17:32:36.479: I/Adreno-EGL(8370): <qeglDrvAPI_eglInitialize:381>: EGL 1.4 QUALCOMM build:  (CL3869936)
08-31 17:32:36.479: I/Adreno-EGL(8370): OpenGL ES Shader Compiler Version: 17.01.11.SPL
08-31 17:32:36.479: I/Adreno-EGL(8370): Build Date: 01/17/14 Fri
08-31 17:32:36.479: I/Adreno-EGL(8370): Local Branch: 
08-31 17:32:36.479: I/Adreno-EGL(8370): Remote Branch: 
08-31 17:32:36.479: I/Adreno-EGL(8370): Local Patches: 
08-31 17:32:36.479: I/Adreno-EGL(8370): Reconstruct Branch: 
08-31 17:32:36.549: D/dalvikvm(8370): DexOpt: --- END 'ads-1174894372.jar' (success) ---
08-31 17:32:36.549: D/dalvikvm(8370): DEX prep '/data/data/com.example.f/cache/ads-1174894372.jar': unzip in 0ms, rewrite 120ms
08-31 17:32:36.579: E/GooglePlayServicesUtil(8370): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
08-31 17:32:36.589: W/Ads(8370): Not enough space to show ad. Needs 320x50 dp, but only has 286x535 dp.
08-31 17:32:36.619: D/OpenGLRenderer(8370): Enabling debug mode 0
08-31 17:32:36.689: W/Ads(8370): Not enough space to show ad. Needs 320x50 dp, but only has 286x535 dp.
08-31 17:32:36.699: I/dalvikvm(8370): Total arena pages for JIT: 11
08-31 17:32:36.699: I/dalvikvm(8370): Total arena pages for JIT: 12
08-31 17:32:36.699: I/dalvikvm(8370): Total arena pages for JIT: 13
08-31 17:32:36.699: I/dalvikvm(8370): Total arena pages for JIT: 14
08-31 17:32:36.699: E/GooglePlayServicesUtil(8370): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
08-31 17:32:36.729: E/GooglePlayServicesUtil(8370): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
08-31 17:32:36.739: E/GooglePlayServicesUtil(8370): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
08-31 17:32:38.531: W/Ads(8370): Not enough space to show ad. Needs 320x50 dp, but only has 286x535 dp.
08-31 17:32:38.531: I/Ads(8370): Scheduling ad refresh 60000 milliseconds from now.
08-31 17:32:38.531: I/Ads(8370): Ad finished loading.
08-31 17:33:38.540: I/Ads(8370): Starting ad request.
08-31 17:33:38.540: I/Ads(8370): Use AdRequest.Builder.addTestDevice("4F1AF66A4340D91DEDBA62394D3A289B") to get test ads on this device.
08-31 17:33:38.550: I/Ads(8370): Please set theme of AdActivity to @android:style/Theme.Translucent to enable transparent background interstitial ad.
08-31 17:33:38.580: W/Ads(8370): Not enough space to show ad. Needs 320x50 dp, but only has 286x535 dp.
08-31 17:33:38.590: E/GooglePlayServicesUtil(8370): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
08-31 17:33:38.610: E/GooglePlayServicesUtil(8370): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
08-31 17:33:38.650: E/GooglePlayServicesUtil(8370): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
08-31 17:33:38.660: E/GooglePlayServicesUtil(8370): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
08-31 17:33:39.901: I/Ads(8370): Scheduling ad refresh 60000 milliseconds from now.
08-31 17:33:39.901: I/Ads(8370): Ad finished loading.
08-31 17:33:39.911: W/Ads(8370): Not enough space to show ad. Needs 320x50 dp, but only has 286x535 dp.
08-31 17:33:39.911: W/Ads(8370): Not enough space to show ad. Needs 320x50 dp, but only has 286x535 dp.
08-31 17:33:39.931: W/Ads(8370): Not enough space to show ad. Needs 320x50 dp, but only has 286x535 dp.
08-31 17:33:39.931: W/Ads(8370): Not enough space to show ad. Needs 320x50 dp, but only has 286x535 dp.
08-31 17:33:39.951: W/Ads(8370): Not enough space to show ad. Needs 320x50 dp, but only has 286x535 dp.
08-31 17:33:39.951: W/Ads(8370): Not enough space to show ad. Needs 320x50 dp, but only has 286x535 dp.
08-31 17:33:40.001: W/Ads(8370): Not enough space to show ad. Needs 320x50 dp, but only has 286x535 dp.
08-31 17:34:39.899: I/Ads(8370): Starting ad request.
08-31 17:34:39.899: I/Ads(8370): Use AdRequest.Builder.addTestDevice("4F1AF66A4340D91DEDBA62394D3A289B") to get test ads on this device.
08-31 17:34:39.909: I/Ads(8370): Please set theme of AdActivity to @android:style/Theme.Translucent to enable transparent background interstitial ad.
08-31 17:34:39.950: E/GooglePlayServicesUtil(8370): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
08-31 17:34:40.000: E/GooglePlayServicesUtil(8370): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
08-31 17:34:40.020: E/GooglePlayServicesUtil(8370): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
08-31 17:34:40.030: E/GooglePlayServicesUtil(8370): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
08-31 17:34:41.321: I/dalvikvm(8370): Total arena pages for JIT: 15
08-31 17:34:41.531: W/Ads(8370): Not enough space to show ad. Needs 320x50 dp, but only has 286x535 dp.
08-31 17:34:41.541: I/Ads(8370): Scheduling ad refresh 60000 milliseconds from now.
08-31 17:34:41.541: I/Ads(8370): Ad finished loading.
08-31 17:34:41.551: W/Ads(8370): Not enough space to show ad. Needs 320x50 dp, but only has 286x535 dp.
08-31 17:34:41.551: W/Ads(8370): Not enough space to show ad. Needs 320x50 dp, but only has 286x535 dp.
08-31 17:34:41.611: W/Ads(8370): Not enough space to show ad. Needs 320x50 dp, but only has 286x535 dp.
Callum
  • 51
  • 1
  • 7

3 Answers3

0

The Problem is Admob Ads need 320X50 dp space in order to show in your app

you have used relativelayout BUT if you try to change these values

android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"

which are located in dimens.xml change it to 50dp for example, you will see that the ads will not show up.

the point here is no matter what kind of layouts you use the important things is make sure the space is 320X50 dp and this can be found in dimens.xml

0

AdSize.BANNER is 320X50 dp.

For your smaller device, instead of

adView.setAdSize(AdSize.BANNER);

You can use:

adView.setAdSize(new AdSize(286, 50));
user846316
  • 6,037
  • 6
  • 31
  • 40
0

I had a similar problem and from this line:

Not enough space to show ad. Needs 320x50 dp, but only has 286x535 dp.

Your log above shows that the there is enough height but not enough width. Therefore you have to ensure that the properties listed below allows enough width for your ad to show. So you can just set them to zero for the first two as shown below and do something appropriate for the last.

android:paddingLeft="0dp"
android:paddingRight="0dp" and 
android:layout_width
Wtower
  • 18,848
  • 11
  • 103
  • 80
wadleo
  • 101
  • 7