Ad banner not show up
Asked Answered
L

5

5

I was learn Adbanner from Admobs in this link https://developers.google.com/admob/android/quick-start but when i test my application in device and emulator there is no Adbanner show in my application

i got this following error in Stacktrace

java.lang.NullPointerException
    at android.os.Handler.<init>(Handler.java:157)
    at com.google.android.gms.ads.internal.util.client.zza.<clinit>(Unknown Source)
    at com.google.android.gms.ads.internal.client.zzk.<init>(Unknown Source)
    at com.google.android.gms.ads.internal.client.zzk.<clinit>(Unknown Source)
    at com.google.android.gms.ads.internal.client.zzy.<init>(Unknown Source)
    at com.google.android.gms.ads.internal.client.zzy.<init>(Unknown Source)
    at com.google.android.gms.ads.internal.client.zzy.<init>(Unknown Source)
    at com.google.android.gms.ads.AdView.<init>(Unknown Source)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.instantiateClass(ProjectCallback.java:442)
    at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.loadView(ProjectCallback.java:194)
    at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:206)
    at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:131)
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:746)
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:718)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:372)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:371)
    at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:333)
    at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:349)
    at com.android.ide.eclipse.adt.internal.editors.layout.gle2.RenderService.createRenderSession(RenderService.java:519)
    at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.renderWithBridge(GraphicalEditorPart.java:1584)
    at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.recomputeLayout(GraphicalEditorPart.java:1309)
    at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.activated(GraphicalEditorPart.java:1066)
    at com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditorDelegate.delegatePageChange(LayoutEditorDelegate.java:686)
    at com.android.ide.eclipse.adt.internal.editors.common.CommonXmlEditor.pageChange(CommonXmlEditor.java:360)
    at org.eclipse.ui.part.MultiPageEditorPart.setActivePage(MultiPageEditorPart.java:1102)
    at org.eclipse.ui.forms.editor.FormEditor.setActivePage(FormEditor.java:607)
    at com.android.ide.eclipse.adt.internal.editors.AndroidXmlEditor.selectDefaultPage(AndroidXmlEditor.java:450)
    at com.android.ide.eclipse.adt.internal.editors.AndroidXmlEditor.addPages(AndroidXmlEditor.java:311)
    at com.android.ide.eclipse.adt.internal.editors.common.CommonXmlEditor.addPages(CommonXmlEditor.java:285)
    at org.eclipse.ui.forms.editor.FormEditor.createPages(FormEditor.java:138)
    at org.eclipse.ui.part.MultiPageEditorPart.createPartControl(MultiPageEditorPart.java:363)
    at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.createPartControl(CompatibilityPart.java:151)
    at org.eclipse.ui.internal.e4.compatibility.CompatibilityEditor.createPartControl(CompatibilityEditor.java:99)
    at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.create(CompatibilityPart.java:341)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
    at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:898)
    at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:879)
    at org.eclipse.e4.core.internal.di.InjectorImpl.inject(InjectorImpl.java:121)
    at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:345)
    at org.eclipse.e4.core.internal.di.InjectorImpl.make(InjectorImpl.java:264)
    at org.eclipse.e4.core.contexts.ContextInjectionFactory.make(ContextInjectionFactory.java:162)
    at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.createFromBundle(ReflectionContributionFactory.java:104)
    at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.doCreate(ReflectionContributionFactory.java:73)
    at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.create(ReflectionContributionFactory.java:55)
    at org.eclipse.e4.ui.workbench.renderers.swt.ContributedPartRenderer.createWidget(ContributedPartRenderer.java:129)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createWidget(PartRenderingEngine.java:971)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:640)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:746)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$0(PartRenderingEngine.java:717)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$2.run(PartRenderingEngine.java:711)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:695)
    at org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer.showTab(StackRenderer.java:1306)
    at org.eclipse.e4.ui.workbench.renderers.swt.LazyStackRenderer$1.handleEvent(LazyStackRenderer.java:72)
    at org.eclipse.e4.ui.services.internal.events.UIEventHandler$1.run(UIEventHandler.java:40)
    at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:186)
    at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:145)
    at org.eclipse.swt.widgets.Display.syncExec(Display.java:4761)
    at org.eclipse.e4.ui.internal.workbench.swt.E4Application$1.syncExec(E4Application.java:211)
    at org.eclipse.e4.ui.services.internal.events.UIEventHandler.handleEvent(UIEventHandler.java:36)
    at org.eclipse.equinox.internal.event.EventHandlerWrapper.handleEvent(EventHandlerWrapper.java:197)
    at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:197)
    at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:1)
    at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
    at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
    at org.eclipse.equinox.internal.event.EventAdminImpl.dispatchEvent(EventAdminImpl.java:135)
    at org.eclipse.equinox.internal.event.EventAdminImpl.sendEvent(EventAdminImpl.java:78)
    at org.eclipse.equinox.internal.event.EventComponent.sendEvent(EventComponent.java:39)
    at org.eclipse.e4.ui.services.internal.events.EventBroker.send(EventBroker.java:85)
    at org.eclipse.e4.ui.internal.workbench.UIEventPublisher.notifyChanged(UIEventPublisher.java:59)
    at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java:374)
    at org.eclipse.e4.ui.model.application.ui.impl.ElementContainerImpl.setSelectedElement(ElementContainerImpl.java:171)
    at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.hidePart(PartServiceImpl.java:1283)
    at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.hidePart(PartServiceImpl.java:1236)
    at org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer.closePart(StackRenderer.java:1278)
    at org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer.access$4(StackRenderer.java:1260)
    at org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer$11.close(StackRenderer.java:1145)
    at org.eclipse.swt.custom.CTabFolder.onMouse(CTabFolder.java:1921)
    at org.eclipse.swt.custom.CTabFolder$1.handleEvent(CTabFolder.java:335)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4362)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1113)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4180)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3769)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1127)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1018)
    at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:156)
    at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:654)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
    at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:598)
    at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
    at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:139)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:669)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:608)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1515)

as i know from using IDE (eclipse) this problem will happen, so i was test the game on my device but the banner not show up in the bottom of layout

enter image description here

the red background was image and the yellow background was adbanner place that adbanner must show up but it doesn't

i had put this following code in my class as described in google admobs following link above

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;

public class bplay extends Activity implements View.OnClickListener{

    private AdView mBanner;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.bplay);

        mBanner  = (AdView) findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().build();
        mBanner.loadAd(adRequest);

sorry i was not put all of my code because it is to much, and i don't use app compat in my project

<uses-sdk
    android:minSdkVersion="16"
    android:targetSdkVersion="16" />

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />    

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar">
    <meta-data android:name="com.google.android.gms.version"
               android:value="@integer/google_play_services_version" />
    <activity
        android:name=".Ablankscreen"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.google.android.gms.ads.AdActivity"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
        android:theme="@android:style/Theme.Translucent" />

and in my xml layout i was using linear layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="3dp"
    android:background="@drawable/backgroundblankyellow"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/rulesimage"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:scaleType="fitXY"
        android:src="@drawable/playimage"
        android:visibility="visible" />

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

    </com.google.android.gms.ads.AdView>    

</LinearLayout>

U P D A T E D

I got this error in logcat what is that mean?

09-24 22:51:33.318: E/dalvikvm(24493): Could not find class 'com.google.android.gms.common.h.c', referenced from method com.google.android.gms.common.app.GmsApplication.onCreate
09-24 22:52:11.258: E/dalvikvm(25156): Could not find class 'com.google.android.gms.common.h.c', referenced from method com.google.android.gms.common.app.GmsApplication.onCreate
09-24 22:52:28.708: E/dalvikvm(25264): Could not find class 'com.google.android.gms.common.h.c', referenced from method com.google.android.gms.common.app.GmsApplication.onCreate

Did i missing something that make the banner not show up?

Can anyone help me to fix this so the banner will show up? Thank's in Advance

Landtag answered 18/9, 2015 at 15:22 Comment(1)
At what point do you get this exception?Toxophilite
L
4

This does not need much bounty though.

First of all, copy the .jar file in your google play services project -> the libs folder, and paste it in your project libs folder.

right click on it and and goto build path -> add to build path

also i am guessing you exported your application right? well there is this obsfucation tool called Proguard google him-(he causes makes alot of changes to your code)

look for a file in your project called proguard-project.txt open it and add

-keep class com.google.android.gms.ads.**
Lacylad answered 24/9, 2015 at 20:49 Comment(5)
i had do all of that but the banner not show up tooLandtag
sir, would you mind zipping your project? and adding a link to it in your question so i can download and see?@ArchanisterLacylad
maybe later, but i have a question that i forgot to ask EltzLandtag
i forgot to use testdevice before to get test ads on my project so i just put adview code without addTestDevice in there but my Interstitial work fine without addTestDevice before, so did addTestDevice this cause the banner ads won't show up? it is important to use addTestDevice?Landtag
hmm, i do not think so, have you re-checked your adds id?@Archanister addTestDevice tells admob to give you test adds on a particular device. i but you have solved it right?Lacylad
S
4

For testing you should use the following unit id. Paste it in your values/strings.xml

For banner ads:

<string name="banner_ad_unit_id">ca-app-pub-3940256099942544/6300978111</string>

For insterstitial ads it is ca-app-pub-3940256099942544/1033173712 .

Also make sure you've updated the Android Support Library from the SDK Manager, and included the Play Services dependency in app/build.gradle

dependencies {
    ...
    compile 'com.google.android.gms:play-services-ads:7.8.0'
}

Eclipse users, check out the Eclipse with ADT tab on the official Google Dev documentation for steps to install the Play Services library.

Optionally you can refer the commit history of one of my Git repo that demoes the implementation of banner and interstitial ads.

Stites answered 23/9, 2015 at 10:31 Comment(3)
but i was use Eclipse so there is no gradle in there, Did banner ads must need Gradle system to show up on a game or app?Landtag
Ok, I'm not familiar with Eclipse build system, but I'm sure there's a way to add dependencies (or whatever they call it) in Eclipse.Stites
Check the edited answer. I've linked the instructions to install Play Services library in Eclipse.Stites
T
4

if you don't have android studios just install google play service pakage from android sdk manager and then go to C:\Users\your_computer_name\AppData\Local\Android\sdk\extras\google\google_play_services\libproject\google-play-services_lib\libs here you find a jar include that jar in your project then try to run it. hope it will help you

Tocantins answered 24/9, 2015 at 19:41 Comment(1)
AppData folder is usually hiden so please unhide your folder firstTocantins
L
4

This does not need much bounty though.

First of all, copy the .jar file in your google play services project -> the libs folder, and paste it in your project libs folder.

right click on it and and goto build path -> add to build path

also i am guessing you exported your application right? well there is this obsfucation tool called Proguard google him-(he causes makes alot of changes to your code)

look for a file in your project called proguard-project.txt open it and add

-keep class com.google.android.gms.ads.**
Lacylad answered 24/9, 2015 at 20:49 Comment(5)
i had do all of that but the banner not show up tooLandtag
sir, would you mind zipping your project? and adding a link to it in your question so i can download and see?@ArchanisterLacylad
maybe later, but i have a question that i forgot to ask EltzLandtag
i forgot to use testdevice before to get test ads on my project so i just put adview code without addTestDevice in there but my Interstitial work fine without addTestDevice before, so did addTestDevice this cause the banner ads won't show up? it is important to use addTestDevice?Landtag
hmm, i do not think so, have you re-checked your adds id?@Archanister addTestDevice tells admob to give you test adds on a particular device. i but you have solved it right?Lacylad
E
3

According to your stacktrace:

   at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.instantiateClass(ProjectCallback.java:442)
    at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.loadView(ProjectCallback.java:194)

You are attempting to do this from within your IDE. This will never work. Deploy to a device.

Elated answered 19/9, 2015 at 22:29 Comment(0)
O
3

Testing on Emulator for admob is not possible because there is no Google Play services installed on the emulator. So you have to test it on the Real Device or use Jenny Motion Emulator and install Google Play Services over there. and here is example of working code also have a look.

<com.google.android.gms.ads.AdView

    android:id="@+id/adView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    ads:adSize="SMART_BANNER"
    android:layout_alignParentBottom="true"
    ads:adUnitId="Your Key "
    android:visibility="visible"    />
Octavalent answered 29/9, 2015 at 7:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.