Resource Not Found Exception while integrating AdMob - android

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.

Related

Android Admob Integration Doesn't show ad

i've sucessfully integrate Admob in my app . i have my Admob key . but it isn't working . it is not showing ads in app.
This is my XML . this is what i've done so far
<?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:orientation="vertical"
tools:context="com.radioaudio.motivationalaudios.MyYouTubePlayer">
<com.google.android.youtube.player.YouTubePlayerView
android:id="#+id/youtube_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/videoTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="Arise, Awake and stop not till the truth is known - Radio Story | IIT Kanpur Radio"
android:textColor="#000"
android:textSize="20dp" />
<com.google.android.gms.ads.NativeExpressAdView
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adUnitId="ca-app-pub-5059726881726792/7013814664"
ads:adSize="280x132">
</com.google.android.gms.ads.NativeExpressAdView>
</LinearLayout>
my java code
NativeExpressAdView adView = (NativeExpressAdView) findViewById(R.id.adView);
AdRequest request = new AdRequest.Builder()
.addTestDevice("A5E3E2068BD88202CBC281AD76984BEE")
.build();
adView.loadAd(request);
Native ads takes time to show. So kindly wait for 2-3 hours. They will pop up automatically. you might created your Account just a minute ago ..

Showing error Required XML attribute "adSize" was missing

I am implementing banner ads, but getting the error "Required XML attribute "adsize" was missing". I was using the developer.google.com link to add admob
I also visited other stackoverflow questions like as Required XML attribute 'adsize' was missing (google play service)
and I have already implemented everything but the error remains the same. Here is the code.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.abhishek.canddatastructureprograms.MainActivity">
<FrameLayout
android:id="#+id/sample_content_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="#string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
</RelativeLayout>
MainActivity.java
added the following code in onCreate() method.
AdView mAdview= (AdView) findViewById(R.id.adView);
//AdRequest mAdRequest= new AdRequest().Builder.build();
AdRequest request = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR) // All emulators
.addTestDevice("9F099BD5E5700664591DEC5FDC92A40E") // An example device ID
.build();
mAdview.loadAd(request);
Please let me know if I need to add any more details or code.
Code seems to be right. Try to remove all left and right paddings or margins, maybe you get this error because you have too small screen to show add.

"linearLayout cannot be resolved or it is not a field" with AdMob instructions by Google for Android

I am trying to find a solution to my problem by an hour and I found some topics with my similar problem, but I don't understand how to resolve.
I was developing an app with Processing for Android and I wanted to try AdMob (just for learning, for now), so I followed instructions all over the net and now I am stuck.
To add ads in the app, I was following Google instructions to add the SDK of Play Service and to add banners, but I am stuck here:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_main);
initPdService();
// Create an ad.
adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId("ca-app-pu....83399");
// Add the AdView to the view hierarchy. The view will have no size
// until the ad is loaded.
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);
}
The problem is that it give me "linearLayout cannot be resolved or it is not a field", and I don't know how to resolve. I think that the problem is in findViewById(R.id.linearLayout), since the error is at "linearLayout" and not "LinearLayout".
I am sure that a lot of people find this problem, so I think that is a common problem. I already added import android.widget.LinearLayout;at the top of the sketch, so I don't know what is the problem.
Other infos: it is targeting Android SDK 19, as I know that Play Services want at least API level 13.
EDIT:
Here is my [old] activity_main.xml found is /res/layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<android.support.v7.widget.Space
android:id="#+id/space1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/adView"
android:layout_marginTop="208dp"
android:layout_toRightOf="#+id/adView" />
<View
android:id="#+id/view1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
</RelativeLayout>
EDIT 2:
This is my new activity_main.xml, with linearLayout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:orientation="horizontal" >
<android.support.v7.widget.Space
android:id="#+id/space1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/adView"
android:layout_marginTop="208dp"
android:layout_toRightOf="#+id/adView" />
<View
android:id="#+id/view1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
</LinearLayout>
</RelativeLayout>
You need to set your content view:
setContentView(R.layout.activity_main);
which you have commented out. Do you have an xml file "activity_main.xml" that contains the LinearLayout with an id, linearLayout?
If yout don't have a LinearLayout with the id linearLayout, you need to add one. Otherwise, it's trying to find a view (by id!) that doesn't exist. For example:
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:orientation="horizontal" >
...
</LinearLayout>
Your issue is that you are using Processing as a library on top of the Android SDK, and it doesn't have access to the layout files, as in Processing you create your screens programatically - it is similar to one big Canvas class for those that are familiar with Android and not Processing.
What the actual compilation error is saying is that the generated R.java file is not finding the compressed resources
I've never tried to add AdMob, but really i think your issue here is that you need to instantiate a LinearLayout programatically, not via XML - as again, you won't have access to that through the PDE.
EDIT:
just noticed that you are using Eclipse (and LibPd !!)... ok, so you can reach a layout
Can you show the code where you are importing Processing into the Activity ?

Admob not showing in webview

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

com.admob.android.ads.AdView unbound prefix?

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.

Categories

Resources