Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ClassNotFound when trying to implement AdMob banner

Tags:

android

admob

I am getting a very annoying ClassNotFound exception when trying to implement an admob banner in my android app, using admob sdk 4.3.1. I have used the following implementation:

Manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.xxx"
    android:versionCode="1"

    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="10"

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

     <activity android:name="com.google.ads.AdActivity"
    android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>

main.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"

    android:id="@+id/bigmainlayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:background="@color/grey">
 <com.google.ads.AdView android:id="@+id/adView"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         ads:adUnitId="xxxx"
                         ads:adSize="BANNER"
                         ads:testDevices="TEST_EMULATOR"
                         ads:loadAdOnCreate="true"/>
</LinearLayout>

Project.properties

target=android-14

Error:

03-21 22:00:25.993: E/AndroidRuntime(333): FATAL EXCEPTION: main 03-21 22:00:25.993: E/AndroidRuntime(333): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxxx/com.xxxx.MainActivity}: android.view.InflateException: Binary XML file line #125: Error inflating class com.google.ads.AdView 03-21 22:00:25.993: E/AndroidRuntime(333): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647) 03-21 22:00:25.993: E/AndroidRuntime(333): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) 03-21 22:00:25.993: E/AndroidRuntime(333): at android.app.ActivityThread.access$1500(ActivityThread.java:117) 03-21 22:00:25.993: E/AndroidRuntime(333): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) 03-21 22:00:25.993: E/AndroidRuntime(333): at android.os.Handler.dispatchMessage(Handler.java:99) 03-21 22:00:25.993: E/AndroidRuntime(333): at android.os.Looper.loop(Looper.java:123) 03-21 22:00:25.993: E/AndroidRuntime(333): at android.app.ActivityThread.main(ActivityThread.java:3683) 03-21 22:00:25.993: E/AndroidRuntime(333): at java.lang.reflect.Method.invokeNative(Native Method) 03-21 22:00:25.993: E/AndroidRuntime(333): at java.lang.reflect.Method.invoke(Method.java:507) 03-21 22:00:25.993: E/AndroidRuntime(333): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 03-21 22:00:25.993: E/AndroidRuntime(333): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 03-21 22:00:25.993: E/AndroidRuntime(333): at dalvik.system.NativeStart.main(Native Method) 03-21 22:00:25.993: E/AndroidRuntime(333): Caused by: android.view.InflateException: Binary XML file line #125: Error inflating class com.google.ads.AdView 03-21 22:00:25.993: E/AndroidRuntime(333): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581) 03-21 22:00:25.993: E/AndroidRuntime(333): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623) 03-21 22:00:25.993: E/AndroidRuntime(333): at android.view.LayoutInflater.rInflate(LayoutInflater.java:626) 03-21 22:00:25.993: E/AndroidRuntime(333): at android.view.LayoutInflater.inflate(LayoutInflater.java:408) 03-21 22:00:25.993: E/AndroidRuntime(333): at android.view.LayoutInflater.inflate(LayoutInflater.java:320) 03-21 22:00:25.993: E/AndroidRuntime(333): at android.view.LayoutInflater.inflate(LayoutInflater.java:276) 03-21 22:00:25.993: E/AndroidRuntime(333): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207) 03-21 22:00:25.993: E/AndroidRuntime(333): at android.app.Activity.setContentView(Activity.java:1657) 03-21 22:00:25.993: E/AndroidRuntime(333): at com.xxxx.MainActivity.onCreate(FreeMedsActivity.java:55) 03-21 22:00:25.993: E/AndroidRuntime(333): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 03-21 22:00:25.993: E/AndroidRuntime(333): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) 03-21 22:00:25.993: E/AndroidRuntime(333): ... 11 more 03-21 22:00:25.993: E/AndroidRuntime(333): Caused by: java.lang.ClassNotFoundException: com.google.ads.AdView in loader dalvik.system.PathClassLoader[/data/app/com.xxxx-2.apk] 03-21 22:00:25.993: E/AndroidRuntime(333): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240) 03-21 22:00:25.993: E/AndroidRuntime(333): at java.lang.ClassLoader.loadClass(ClassLoader.java:551) 03-21 22:00:25.993: E/AndroidRuntime(333): at java.lang.ClassLoader.loadClass(ClassLoader.java:511) 03-21 22:00:25.993: E/AndroidRuntime(333): at android.view.LayoutInflater.createView(LayoutInflater.java:471) 03-21 22:00:25.993: E/AndroidRuntime(333): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570

)

I get a similar classnotfound exception when creating the adview in code and adding it to the layout. I get this error on OS 2.2, 2.3.3, 2.3.7, and 4.0. I have added the admobsdk.jar to the build path. I have tried switching the minSSdkVersion to 14. I am using eclipse indigo.

I am wondering if this has to do with how I am adding the .jar. I have it copied into a /lib folder in the project, and then either do add to build path or preferences-->build path-->add JAR. I am wondering if somehow the app doesn't know where to find the .jar still...

like image 892
benbeel Avatar asked Mar 22 '12 02:03

benbeel


People also ask

What are AdMob banner ads for Android Studio?

Android | AdMob Banner Ads for Android Studio. Banner ads are rectangular image or text ads that occupy a spot within an app’s layout. If you’re new to mobile advertising, banner ads are the easiest to implement. This article shows you how to integrate banner ads from AdMob into an Android app.

How to integrate Flutter SDK with AdMob?

Because Flutter is a multi-platform SDK, you need to add an app and ad units for both Android and iOS in AdMob. Note:If you want to follow the codelab instead of creating a new application and ad units on your own, go to the Use the test AdMob app and ad unitssection. Set up for Android

How to add banner ad to main activity in Android?

Add the highlighted code to Main Activity to show Banner Ad. Add the Admob App Id and Banner Ad Id to string.xml . Want a more fast-paced & competitive environment to learn the fundamentals of Android?

How to release the resource associated with the bannerad object?

Release the resource associated with the BannerAdobject by calling the BannerAd.dispose()method in the dispose()callback method. banner_inline_page.dart @override void dispose() { // TODO: Dispose a BannerAd object _ad.dispose(); super.dispose(); } That's it! Run the project, and click the Banner inline adbutton from the home page.


1 Answers

Turns out r17 of Android Tools requires the /lib folder to be /libs, and the SDK has to be placed in there and referenced internally in order for it to be included in the apk.

Check out this link for more information.

like image 91
Eric Leichtenschlag Avatar answered Oct 24 '22 14:10

Eric Leichtenschlag