My ads are not showing, i'm trying to add them in my webview application. This is the main.xml code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.google.ads.AdView android:id="#+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adUnitId="a14f3ed10a5e4eb"
ads:adSize="BANNER"
ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
ads:loadAdOnCreate="true"/>
<WebView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
Any suggestion??
you have to give the Specific ID to the addMob. Just see the Default Example on GoogleAddMob site and follow that.
Use debug mode via Eclipse and launch and Sample Ad app from the developer.android.com. In LogCat search for "To get test" with Ctrl+F and you will see the id there.
Or check this link with detailed how to:
Get ad id how to
Related
Im trying to get the google admob sdk integrated to display ads in an android application writen in xml. Yes I have already made sure that admob jar is checked in order and export under build path!
I realize there are other open questions but none of the answers solved my issue! Im getting no errors, my project.properties is set to target 19 and my manifest has this:
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
and I will post my entire main layout page
Please help me guys!
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/imageView1"
android:layout_centerVertical="true"
android:gravity="center"
android:text="#string/text_mainmenu"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF" />
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adUnitId="[MYIDHERE]"
ads:adSize="BANNER"
ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
ads:loadAdOnCreate="true" />
</RelativeLayout>
I had the same issue. There are some issues with the Graphical Layout when you are rendering layouts in Eclipse for Android-19 (KitKat). You cannot change items in the Properties window for example.
Switching to Android-18 in Graphical Layout (green Android top-right) solved the problem for me.
Android 2.3.3
I have followed the steps, found in the this tutorial. When I run the application in my device(mobile), the ads are getting displayed. No Problem here. But when I try to view the activity in my eclipse, I get a blank screen with the NullPointerException. I have taken the screenshot. Please refer to it.
Then, I have clicked on the link, given in the exception's "detail" (SourceFile:670) and I get the following details..
I have clicked on the Add Source, and browsed to the jar file in my application->libs folder. Then I get the following...
Here are my xml and java codes that I have used...
XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="140dp"
android:background="#000000"
android:orientation="vertical" >
<com.google.ads.AdView android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="a151xxxxxxxxx"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"/>
<TextView
android:id="#+id/txtViewPrevious"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:gravity="right"
android:height="25dp"
android:singleLine="true"
android:text=""
android:textSize="16sp" />
.....
.....
Java
private AdView adView;
adView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest();
adView.loadAd(adRequest);
Libs
How do i get rid of these exceptions?
Thanks in Advance...
This happens. It's normal. Eclipse can't display custom views sometimes (most of the time actually).
Download the latest SDK. Per the release notes, this was fixed in v6.3.0.
I'm using adMob sdk 4.3.1 for android and am using xml to create the layout as explained here using Eclipse IDE. The problem is that eclipse doesn't recognize the com.google.ads.AdView tag and gives the error error: error parsing XML: unbound prefix. How do I fix this?
EDIT-Here's the code for the layout file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.google.ads.AdView android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="MY_AD_UNIT_ID"
ads:adSize="BANNER"
ads:testDevices="TEST_EMULATOR,e78b974e6ab65648b52951e69edcb571"
ads:loadAdOnCreate="true"/>
</LinearLayout>
Just add xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" to the layout!
I'm just guessing here, you'll have to post your xml (obviously):
You're missing xmlns:android="http://schemas.android.com/apk/res/android" or you've spelt something wrong.
I have a webview in my app, that's it. I tested it, its working but when i add admob to the code, it starts force closing. I did some commenting to see what's causing it to close and when i remove the Abmob related code from main.xml, it starts working normally.
Main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<WebView
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="800dp" />
<com.admob.android.ads.AdView
android:id="#+id/ad"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adUnitId="a14d--mypub--id--"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"/> />
</RelativeLayout>
Can Anybody tell me what i am doing wrong?
You need not to take web view for displaying Admob.
Just remove web iew from your xml file then run your application , it will work.else provide that Admob code in separate layout tag.
<com.admob.android.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res/**Prove Your Package name,e.g. com.xyz.abc**"
android:id="#+id/ad"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adUnitId="a14d--mypub--id--"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"/>
I tried to include admob to an Android app in Eclipse. But I get an error in the layout.xml. Eclipse tells me that com.admot.android.ads.AdView is an unbound prefix. I have the admob library included in the build path, following the pdf instruction. But it still does not seem to find the AdView class. But why?
Here is the layout producing the error:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/renegrothmann.kalah"
android:layout_width="wrap_content" android:layout_height="wrap_content"
>
<renegrothmann.kalah.GameView
android:id="#+id/gameView" android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="2px"
/>
<com.admob.android.ads.AdView
android:id="#+id/ad"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
myapp:backgroundColor="#000000"
myapp:primaryTextColor="#FFFFFF"
myapp:secondaryTextColor="#CCCCCC"
/>
</LinearLayout>
I had the same error wit this layout
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/topLayout"
>
<!-- Ad Placeholder -->
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="a14df07c16f171a"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"
/>
</RelativeLayout>
Then I made it:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/topLayout"
>
<!-- Ad Placeholder -->
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="a14df07c16f171a"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"
/>
</RelativeLayout>
Notice the second xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" in my RelativeLayout in the second example?
In fact if you remove the android namespace declaration xmlns:android="http://schemas.android.com/apk/res/android" it will start moaning about all the android components too.
Change the following
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/renegrothmann.kalah"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
by
<LinearLayout
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/renegrothmann.kalah"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
For me it's working with
<TableLayout
android:id="#+id/resultsuperlotto"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" />
Cheers!
Actually, you do not need to add xmlns:ads to a root element (or a parent element).
You can simply add xmlns:ads property to your AdView element, like:
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
...>
</com.google.android.gms.ads.AdView>
Check this page.
Maybe you should replace "myapp" at the bottom with "app" or replace "xmlns:app" at the top with "xmlns:myapp". They should probably be the same.
I cannot provide a real answer, since actually I do not know, why it works now. What I did: I restarted with a fresh project. Sometimes, you simply go one wrong step!
Right Click your project, click Properties, click Android, on the Library panel click Add Button
and add both google-play-services_lib and appcompat_v7 libraries
Apply, Refresh, Clean under the Project.
If this doesn't work try the following:
Change the target line in project.properties as target=android-13
Right click on your project and Click Refresh
Click Clean under Project
Hope this will work.