我已经创建了一个用于测试admob广告的Android应用,但是当我运行它时,它会强行关闭。 我的主要活动: -
package com.dibdev.bmicalculator;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class BMI_Calculator extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bmi__calculator);
}}
我的清单。我认为这里没有任何错误....: -
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dibdev.bmicalculator"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<activity
android:name=".BMI_Calculator"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />
</activity>
</application>
我的布局文件。我在com.google中包含了xmlns ......它是否正确?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
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="com.dibdev.bmicalculator.BMI_Calculator" >
<com.google.android.gms.ads.AdView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="SAMPLE"
ads:startOnCreate="True" >
</com.google.android.gms.ads.AdView>
我的Logcat: -
11-08 14:37:58.161: I/System.out(25610): Sending WAIT chunk
11-08 14:37:58.161: W/ActivityThread(25610): Application com.dibdev.bmicalculator is waiting for the debugger on port 8100...
11-08 14:37:58.176: I/dalvikvm(25610): Debugger is active
11-08 14:37:58.361: I/System.out(25610): Debugger has connected
11-08 14:37:58.456: I/System.out(25610): waiting for debugger to settle...
11-08 14:37:58.656: I/System.out(25610): waiting for debugger to settle...
11-08 14:37:58.856: I/System.out(25610): waiting for debugger to settle...
11-08 14:37:59.056: I/System.out(25610): waiting for debugger to settle...
11-08 14:37:59.256: I/System.out(25610): waiting for debugger to settle...
11-08 14:37:59.456: I/System.out(25610): waiting for debugger to settle...
11-08 14:37:59.661: I/System.out(25610): debugger has settled (1310)
11-08 14:37:59.681: E/dalvikvm(25610): dvmPauseGc(AppLaunch) called - cookie=0x47d7 (f=0x1)
11-08 14:37:59.691: I/PersonaManager(25610): getPersonaService() name persona_policy
11-08 14:37:59.741: D/skia(25610): GFXPNG PNG bitmap created width:48 height:48 bitmap id is 180
11-08 14:37:59.751: D/skia(25610): GFXPNG PNG bitmap created width:72 height:72 bitmap id is 181
11-08 14:37:59.766: D/skia(25610): GFXPNG PNG bitmap created width:72 height:72 bitmap id is 182
11-08 14:37:59.781: D/skia(25610): GFXPNG PNG bitmap created width:13 height:41 bitmap id is 183
11-08 14:37:59.786: D/skia(25610): GFXPNG PNG bitmap created width:18 height:18 bitmap id is 184
11-08 14:37:59.791: D/skia(25610): GFXPNG PNG bitmap created width:18 height:18 bitmap id is 185
11-08 14:37:59.801: D/skia(25610): GFXPNG PNG bitmap created width:18 height:18 bitmap id is 186
11-08 14:37:59.836: E/MoreInfoHPW_ViewGroup(25610): Parent view is not a TextView
11-08 14:37:59.861: D/skia(25610): GFXPNG PNG bitmap created width:72 height:72 bitmap id is 187
11-08 14:37:59.871: D/skia(25610): GFXPNG PNG bitmap created width:72 height:72 bitmap id is 188
11-08 14:37:59.881: D/skia(25610): GFXPNG PNG bitmap created width:72 height:72 bitmap id is 189
11-08 14:37:59.911: W/dalvikvm(25610): VFY: unable to resolve static field 1355 (AdsAttrs) in Lcom/google/android/gms/R$styleable;
11-08 14:37:59.911: D/dalvikvm(25610): VFY: replacing opcode 0x62 at 0x0009
11-08 14:37:59.916: I/dalvikvm(25610): DexOpt: unable to optimize static field ref 0x054c at 0x0f in Lcom/google/android/gms/internal/bb;.<init>
11-08 14:37:59.916: I/dalvikvm(25610): DexOpt: unable to optimize static field ref 0x054d at 0x15 in Lcom/google/android/gms/internal/bb;.<init>
11-08 14:37:59.921: I/dalvikvm(25610): DexOpt: unable to optimize static field ref 0x054e at 0x32 in Lcom/google/android/gms/internal/bb;.<init>
11-08 14:38:00.911: D/dalvikvm(25610): threadid=1: still suspended after undo (sc=1 dc=1)
答案 0 :(得分:1)
我认为您错过了清单中BMI_Calculator活动的活动结束标记。 如果不是这样,请发布堆栈跟踪。
答案 1 :(得分:0)
在最新广告sdk中,您需要为gms版本添加元标记,并在menifest文件中添加您忘记添加的广告声明。
整数值可能与您的值不同,您可以在debunging时在日志中获取它。
<meta-data
android:name="com.google.android.gms.version"
android:value="6111000" />
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />