自从我每次运行时将 AdMob 包含到我的应用程序中并单击一个按钮,该按钮会转到一个带有广告的页面
主要java:
package com.co500.gdsg;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class GameDevStoryGuideActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button co = (Button) findViewById(R.id.combinations);
co.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.co500.gdsg.COMBINATIONS"));
}
});
Button jb = (Button) findViewById(R.id.jobs);
jb.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.co500.gdsg.JOBS"));
}
});
Button ty = (Button) findViewById(R.id.type);
ty.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.co500.gdsg.TYPE"));
}
});
Button con = (Button) findViewById(R.id.consoles);
con.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.co500.gdsg.CONSOLES"));
}
});
Button gen = (Button) findViewById(R.id.genre);
gen.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.co500.gdsg.GENRE"));
}
});
}
}
显现
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:installLocation="preferExternal"
package="com.co500.gdsg"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" />/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name="com.google.ads.AdActivity"
android:configChanges="orientation|keyboard|keyboardHidden|screenLayout|uiMode|screenSize|smallestScreenSize"
></activity>
<activity
android:name=".GameDevStoryGuideActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Genre"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.co500.gdsg.GENRE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Combinations"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.co500.gdsg.COMBINATIONS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Consoles"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.co500.gdsg.CONSOLES" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Notgood"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.co500.gdsg.NOTGOOD" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Hmm"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.co500.gdsg.HMM" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Notbad"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.co500.gdsg.NOTBAD" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Creative"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.co500.gdsg.CREATIVE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Amazing"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.co500.gdsg.AMAZING" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Jobs"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.co500.gdsg.JOBS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Type"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.co500.gdsg.TYPE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
主要的.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background"
android:gravity="center"
android:orientation="vertical" >
<Button
android:id="@+id/genre"
android:layout_width="148dp"
android:layout_height="wrap_content"
android:text="Game Genre Unlocks" />
<Button
android:id="@+id/consoles"
android:layout_width="148dp"
android:layout_height="wrap_content"
android:text="Consoles" />
<Button
android:id="@+id/combinations"
android:layout_width="148dp"
android:layout_height="wrap_content"
android:text="Combinations" />
<Button
android:id="@+id/type"
android:layout_width="148dp"
android:layout_height="wrap_content"
android:text="Game Type Unlocks" />
<Button
android:id="@+id/jobs"
android:layout_width="148dp"
android:layout_height="wrap_content"
android:text="Jobs" />
</LinearLayout>
consoles.xml(与其他 xml 类似)
<?xml version="1.0" encoding="utf-8"?>
<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:orientation="vertical" >
<ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/consoleavail" />
</LinearLayout>
</ScrollView>
<com.google.ads.AdView android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
ads:adUnitId="empty for a reason"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"/>
</RelativeLayout>
日志猫:
07-13 15:16:13.770: D/dalvikvm(4567): GC_FOR_ALLOC freed 17K, 2% free 7848K/8007K, paused 14ms
07-13 15:16:13.780: I/dalvikvm-heap(4567): Grow heap (frag case) to 9.377MB for 1769056-byte allocation
07-13 15:16:13.810: D/dalvikvm(4567): GC_CONCURRENT freed 2K, 2% free 9573K/9735K, paused 2ms+2ms
07-13 15:16:13.830: D/AndroidRuntime(4567): Shutting down VM
07-13 15:16:13.830: W/dalvikvm(4567): threadid=1: thread exiting with uncaught exception (group=0x40a3b1f8)
07-13 15:16:13.830: E/AndroidRuntime(4567): FATAL EXCEPTION: main
07-13 15:16:13.830: E/AndroidRuntime(4567): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.co500.gdsg/com.co500.gdsg.Consoles}: android.view.InflateException: Binary XML file line #23: Error inflating class com.google.ads.AdView
07-13 15:16:13.830: E/AndroidRuntime(4567): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
07-13 15:16:13.830: E/AndroidRuntime(4567): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)