私はAdMobを初めて使用しますが、エラーが発生して混乱しています。誰か助けてもらえますか?アプリを起動するたびに、強制終了します。以前にAdMobを使用せずに試したことがあるため、アプリ自体が機能することはわかっています...メインクラスは次のとおりです。packagecom.firecow.markcheck;
package com.firecow.markcheck;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.text.Editable;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Toast;
import com.google.ads.*;
public class MarkCheck extends Activity {
/** Called when the activity is first created. */
Button sub, share;
EditText per;
Context context;
CharSequence text;
String heightString;
double num;
Toast toast;
MediaPlayer player;
private AdView adView;
AdRequest adRequest = new AdRequest();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
sub = (Button) findViewById(R.id.bSubmit);
share = (Button) findViewById(R.id.bShare);
per = (EditText) findViewById(R.id.tePercent);
context = getApplicationContext();
final int duration = Toast.LENGTH_SHORT;
adRequest.addTestDevice(AdRequest.TEST_EMULATOR); // Emulator
adRequest.addTestDevice("EMJY-KBBS-VL7P-2"); // Test Android Device
//Create the adView
adView = new AdView(this, AdSize.BANNER, "a14fd022edb48e8");
// Lookup your LinearLayout assuming it’s been given
// the attribute android:id="@+id/mainLayout"
LinearLayout layout = (LinearLayout) findViewById(R.id.mainLayout);
// Add the adView to it
layout.addView(adView);
// Initiate a generic request to load it with an ad
adView.loadAd(adRequest);
text = "Made by Firecow, Voice of William Wang";
toast = Toast.makeText(context, text, duration);
toast.show();
sub.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
heightString = per.getText().toString();
if (heightString != null) {
num = Double.parseDouble(heightString);
if (num >= 151) {
text = "I didn't know you could score that high...";
toast = Toast.makeText(context, text, duration);
toast.show();
} else if (num >= 101) {
text = "You get a A+";
toast = Toast.makeText(context, text, duration);
player = MediaPlayer.create(getApplicationContext(),
R.raw.perfect);
player.start();
toast.show();
} else if (num >= 86) {
text = "You get a A";
toast = Toast.makeText(context, text, duration);
player = MediaPlayer.create(getApplicationContext(),
R.raw.harvard);
player.start();
toast.show();
} else if (num >= 73) {
text = "You get a B";
toast = Toast.makeText(context, text, duration);
player = MediaPlayer.create(getApplicationContext(),
R.raw.ucla);
player.start();
toast.show();
} else if (num >= 68) {
text = "You get a C+";
toast = Toast.makeText(context, text, duration);
player = MediaPlayer.create(getApplicationContext(),
R.raw.kwantlan);
player.start();
toast.show();
} else if (num >= 60) {
text = "You get a C";
toast = Toast.makeText(context, text, duration);
player = MediaPlayer.create(getApplicationContext(),
R.raw.wendys);
player.start();
toast.show();
} else if (num >= 50) {
text = "You get a C-";
toast = Toast.makeText(context, text, duration);
player = MediaPlayer.create(getApplicationContext(),
R.raw.drop_out);
player.start();
toast.show();
} else if (num <= 49) {
text = "You get a F";
toast = Toast.makeText(context, text, duration);
player = MediaPlayer.create(getApplicationContext(),
R.raw.failure);
player.start();
toast.show();
} else {
text = "Please type a proper percent";
toast = Toast.makeText(context, text, duration);
toast.show();
}
} else {
text = "Please enter a proper percent";
toast = Toast.makeText(context, text, duration);
toast.show();
}
}
});
share.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent bacon = new Intent("com.firecow.markcheck.SHARE");
startActivity(bacon);
}
});
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
try {
if (adView != null) {
adView.destroy();
}
player.release();
finish();
} catch (Exception E) {
}
}
}
と私のマニフェスト:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.firecow.markcheck"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".MarkCheck"
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=".Share"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.firecow.markcheck.SHARE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.google.ads.AdActivity"
/>
</application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
私はすっごく混乱しています...助けてください!