嗨,我刚刚完成我的应用程序。我如何将Admob广告添加到我的应用程序,我已经尝试了一切,似乎有一种新的方式来做到谷歌游戏...无论如何,如果有人知道它是如何一步一步PLZ让我知道它是怎么回事? / p>
我的xml
<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"
<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adUnitId="XXXXXXX"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"
/>
和我的java
我对ADmob一无所知
我的Mainfest
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
我试着遵循这个啧啧
https://developers.google.com/mobile-ads-sdk/docs/
无论如何我没有错误但是当我尝试运行应用程序时我会收到此错误
不幸的是,Windows已停止
我的logCat说
07-13 12:15:56.909: E/AndroidRuntime(1263): at android.app.ActivityThread.access$800(ActivityThread.java:135)
07-13 13:09:17.099: E/AndroidRuntime(1464): FATAL EXCEPTION: main
07-13 13:09:17.099: E/AndroidRuntime(1464): Process: win.example.windows, PID: 1464
07-13 13:09:17.099: E/AndroidRuntime(1464): java.lang.RuntimeException: Unable to start activity ComponentInfo{win.example.windows/win.example.windows.Main}: android.view.InflateException: Binary XML file line #31: Error inflating class com.google.ads.AdView
07-13 13:09:17.099: E/AndroidRuntime(1464): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
07-13 13:09:17.099: E/AndroidRuntime(1464): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
07-13 13:09:17.099: E/AndroidRuntime(1464): at android.app.ActivityThread.access$800(ActivityThread.java:135)
07-13 13:09:17.099: E/AndroidRuntime(1464): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
07-13 13:09:17.099: E/AndroidRuntime(1464): at android.os.Handler.dispatchMessage(Handler.java:102)
07-13 13:09:17.099: E/AndroidRuntime(1464): at android.os.Looper.loop(Looper.java:136)
07-13 13:09:17.099: E/AndroidRuntime(1464): at android.app.ActivityThread.main(ActivityThread.java:5017)
07-13 13:09:17.099: E/AndroidRuntime(1464): at java.lang.reflect.Method.invokeNative(Native Method)
07-13 13:09:17.099: E/AndroidRuntime(1464): at java.lang.reflect.Method.invoke(Method.java:515)
07-13 13:09:17.099: E/AndroidRuntime(1464): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
07-13 13:09:17.099: E/AndroidRuntime(1464): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
07-13 13:09:17.099: E/AndroidRuntime(1464): at dalvik.system.NativeStart.main(Native Method)
07-13 13:09:17.099: E/AndroidRuntime(1464): Caused by: android.view.InflateException: Binary XML file line #31: Error inflating class com.google.ads.AdView
07-13 13:09:17.099: E/AndroidRuntime(1464): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707)
07-13 13:09:17.099: E/AndroidRuntime(1464): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
07-13 13:09:17.099: E/AndroidRuntime(1464): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
07-13 13:09:17.099: E/AndroidRuntime(1464): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
07-13 13:09:17.099: E/AndroidRuntime(1464): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
07-13 13:09:17.099: E/AndroidRuntime(1464): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
07-13 13:09:17.099: E/AndroidRuntime(1464): at android.app.Activity.setContentView(Activity.java:1929)
07-13 13:09:17.099: E/AndroidRuntime(1464): at android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:216)
07-13 13:09:17.099: E/AndroidRuntime(1464): at android.support.v7.app.ActionBarActivityDelegateICS.setContentView(ActionBarActivityDelegateICS.java:110)
07-13 13:09:17.099: E/AndroidRuntime(1464): at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:76)
07-13 13:09:17.099: E/AndroidRuntime(1464): at win.example.windows.Main.onCreate(Main.java:25)
07-13 13:09:17.099: E/AndroidRuntime(1464): at android.app.Activity.performCreate(Activity.java:5231)
07-13 13:09:17.099: E/AndroidRuntime(1464): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
07-13 13:09:17.099: E/AndroidRuntime(1464): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
07-13 13:09:17.099: E/AndroidRuntime(1464): ... 11 more
07-13 13:09:17.099: E/AndroidRuntime(1464): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.ads.AdView" on path: DexPathList[[zip file "/data/app/win.example.windows-2.apk"],nativeLibraryDirectories=[/data/app-lib/win.example.windows-2, /system/lib]]
07-13 13:09:17.099: E/AndroidRuntime(1464): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
07-13 13:09:17.099: E/AndroidRuntime(1464): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
07-13 13:09:17.099: E/AndroidRuntime(1464): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
07-13 13:09:17.099: E/AndroidRuntime(1464): at android.view.LayoutInflater.createView(LayoutInflater.java:559)
07-13 13:09:17.099: E/AndroidRuntime(1464): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
07-13 13:09:17.099: E/AndroidRuntime(1464): ... 24 more
答案 0 :(得分:2)
好吧最后我修好了
首先我的xml应该是这样的
xmlns:ads="http://schemas.android.com/apk/res-auto"
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adUnitId="ca-app-pub-4863046628273331/4657543401"
ads:adSize="BANNER"
/>
和我的java
AdView adView = (AdView) this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
和主要的快速是
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
和
当您将此代码添加到mainfest时,您将收到错误您可以通过执行此操作来修复它
Eclipse - &gt;导入 - &gt;现有的Android代码 - &gt;浏览 - &gt;导航到google-play-services_lib文件夹(android-sdk / extras / google / google_play_services / libproject)。
然后,在您的项目中,控制点击 - &gt;属性 - &gt; android - &gt;库,添加 - &gt;选择刚刚导入的项目 - &gt;确定
之后它应该完美无缺
这里有任何帮助^^