-1

嗨,我第一次尝试为我的应用添加 admob。我已经阅读了很多信息(包括 stackOverFlow)。但是我仍然没有运气。我的应用程序强制关闭。这是我到目前为止的尝试方式。

Androidmanifest.xml

我在应用程序标签中添加了这些行

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

而且我之前还添加了以下行

<Meta-Data android:value="a14f9xxxxx(id from admob)" android:name="ADMOB_PUBLISHER_ID"/>

属性.xml

<?xml version="1.0" encoding="utf-8"?>
  <resources>
    <declare-styleable name="com.admob.android.ads.AdView">            
       <attr name="backgroundColor" format="color" />
       <attr name="primaryTextColor" format="color" />
       <attr name="secondaryTextColor" format="color" />
       <attr name="keywords" format="string" />
       <attr name="refreshInterval" format="integer" />
    </declare-styleable>
  </resources>

frontpage.xml(我的首页活动的布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:myapp="http://schemas.android.com/apk/res/simple.stocktaketrial"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:orientation="vertical" >
...
some other layout and components here
...

<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>

我在 lib 文件夹中添加了 GoogleAdMobAdsSdk-6.0.0 并构建了通行证。

我做错了什么??

我已经阅读了在布局中在xml中添加admob的方式比在java中添加代码更好。因此,如果这是真的,我想保留它。

提前感谢您的帮助。

这是输出的logcat。

06-27 12:24:56.630: E/AndroidRuntime(25265): FATAL EXCEPTION: main
06-27 12:24:56.630: E/AndroidRuntime(25265): java.lang.RuntimeException: Unable to start activity ComponentInfo{simple.stocktaketrial/simple.stocktaketrial.FrontPage}: android.view.InflateException: Binary XML file line #77: Error inflating class com.admob.android.ads.AdView
06-27 12:24:56.630: E/AndroidRuntime(25265):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
06-27 12:24:56.630: E/AndroidRuntime(25265):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
06-27 12:24:56.630: E/AndroidRuntime(25265):    at android.app.ActivityThread.access$2300(ActivityThread.java:125)
06-27 12:24:56.630: E/AndroidRuntime(25265):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
06-27 12:24:56.630: E/AndroidRuntime(25265):    at android.os.Handler.dispatchMessage(Handler.java:99)
06-27 12:24:56.630: E/AndroidRuntime(25265):    at android.os.Looper.loop(Looper.java:123)
06-27 12:24:56.630: E/AndroidRuntime(25265):    at android.app.ActivityThread.main(ActivityThread.java:4627)
06-27 12:24:56.630: E/AndroidRuntime(25265):    at java.lang.reflect.Method.invokeNative(Native Method)
06-27 12:24:56.630: E/AndroidRuntime(25265):    at java.lang.reflect.Method.invoke(Method.java:521)
06-27 12:24:56.630: E/AndroidRuntime(25265):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
06-27 12:24:56.630: E/AndroidRuntime(25265):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
06-27 12:24:56.630: E/AndroidRuntime(25265):    at dalvik.system.NativeStart.main(Native Method)
06-27 12:24:56.630: E/AndroidRuntime(25265): Caused by: android.view.InflateException: Binary XML file line #77: Error inflating class com.admob.android.ads.AdView
06-27 12:24:56.630: E/AndroidRuntime(25265):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
06-27 12:24:56.630: E/AndroidRuntime(25265):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
06-27 12:24:56.630: E/AndroidRuntime(25265):    at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
06-27 12:24:56.630: E/AndroidRuntime(25265):    at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
06-27 12:24:56.630: E/AndroidRuntime(25265):    at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
06-27 12:24:56.630: E/AndroidRuntime(25265):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
06-27 12:24:56.630: E/AndroidRuntime(25265):    at android.app.Activity.setContentView(Activity.java:1647)
06-27 12:24:56.630: E/AndroidRuntime(25265):    at simple.stocktaketrial.FrontPage.onCreate(FrontPage.java:25)
06-27 12:24:56.630: E/AndroidRuntime(25265):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-27 12:24:56.630: E/AndroidRuntime(25265):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
06-27 12:24:56.630: E/AndroidRuntime(25265):    ... 11 more
06-27 12:24:56.630: E/AndroidRuntime(25265): Caused by: java.lang.ClassNotFoundException: com.admob.android.ads.AdView in loader dalvik.system.PathClassLoader[/data/app/simple.stocktaketrial-2.apk]
06-27 12:24:56.630: E/AndroidRuntime(25265):    at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
06-27 12:24:56.630: E/AndroidRuntime(25265):    at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
06-27 12:24:56.630: E/AndroidRuntime(25265):    at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
06-27 12:24:56.630: E/AndroidRuntime(25265):    at android.view.LayoutInflater.createView(LayoutInflater.java:466)
06-2 7 12:24:56.630: E/AndroidRuntime(25265):   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
06-27 12:24:56.630: E/AndroidRuntime(25265):    ... 20 more
4

1 回答 1

0

看起来您缺少 AndroidManifest.xml 中的活动以及“元数据”的不正确大小写...

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="...." android:versionCode=".." android:versionName="...">
   <application android:icon="...." android:label="....">
      <activity ..... >
      </activity>
      <meta-data android:value="a14f9xxxxx(id from admob)" android:name="ADMOB_PUBLISHER_ID"/>
      <activity android:name="com.google.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
   </application>
</manifest>

上述 configChanges 属性适用于 Android SDK 级别 14 及以上。

对于较低的,使用这个:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
       package="...." android:versionCode=".." android:versionName="...">
   <application android:icon="...." android:label="....">
      <activity ..... >
      </activity>
      <meta-data android:value="a14f9xxxxx(id from admob)" android:name="ADMOB_PUBLISHER_ID"/>
      <activity android:name="com.google.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation"/>
    </application>
</manifest>

那里的活动在 Admobs 库中,无需做任何额外的事情 :)

于 2012-06-27T01:08:29.733 回答