我做了一个简单的应用程序,在大量设备上测试得很好,所以我想我会尝试使用AdMob,但现在我的应用程序崩溃了(设备加载一个空的黑屏,然后很快崩溃,消息“不幸的是,(app)停止了”)。在这一点上任何帮助都是巨大的!
清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.XXXXXX.XXXXXX"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/z_icon"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.XXXXXX.XXXXXX.MainActivity"
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="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|
screenSize|smallestScreenSize" />
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
</manifest>
爪哇:
package com.XXXXXX.XXXXXX;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.ErrorDialogFragment;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.AdSize;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.content.Intent;
import android.content.res.Configuration;
import android.net.Uri;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.Toast;
import android.app.Activity;
import android.app.Dialog;
public class MainActivity extends Activity {
ImageButton b1, b2, b3, b4, b5, b6, b7;
private AdView adView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
adView = (AdView)findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
[SEVERAL IMAGE BUTTONS]
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.main_activity_menu, menu);
return true;
}
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
// TODO Auto-generated method stub
switch(item.getItemId()){
case R.id.rateApp:
Intent i = new
Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("market://details?id=com.XXXXXX.XXXXXX"));
startActivity(i);
break;
}
return false;
}
private boolean googlePlayServicesConnected()
{
// Check that Google Play services is available
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
// If Google Play services is available
if (resultCode == ConnectionResult.SUCCESS)
{
// Continue
return true;
} else // Google Play services was not available for some reason
{
Toast.makeText(this, "Google Services Error", Toast.LENGTH_SHORT);
}
return false;
}
}
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:background="@drawable/z_background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="32dp"
android:layout_marginBottom="2dp"
android:layout_marginTop="32dp"
android:gravity="center|center_horizontal" >
<ImageButton
android:id="@+id/b_g"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_margin="3dp"
android:padding="0dp"
android:scaleType="fitCenter"
android:src="@drawable/g_z" />
<ImageButton
android:id="@+id/b_f"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_margin="3dp"
android:padding="0dp"
android:scaleType="fitCenter"
android:src="@drawable/f_z" />
<ImageButton
android:id="@+id/b_y"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_margin="3dp"
android:padding="0dp"
android:scaleType="fitCenter"
android:src="@drawable/y_z" />
<ImageButton
android:id="@+id/b_y2"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_margin="3dp"
android:padding="0dp"
android:scaleType="fitCenter"
android:src="@drawable/y2_z" />
<ImageButton
android:id="@+id/b_a"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_margin="3dp"
android:padding="0dp"
android:scaleType="fitCenter"
android:src="@drawable/a_z" />
<ImageButton
android:id="@+id/b_w"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_margin="3dp"
android:padding="0dp"
android:scaleType="fitCenter"
android:src="@drawable/w_z" />
<ImageButton
android:id="@+id/b_l"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_margin="3dp"
android:padding="0dp"
android:scaleType="fitCenter"
android:src="@drawable/l_z" />
</LinearLayout>
//I’VE TRIED THE FOLLOWING CODE WITH AND WITHOUT ITS OWN EMBEDDED RELATIVE LAYOUT, AS SHOWN ON
//THE GOOGLE DEVELOPER’S SITE]
<com.google.android.gms.ads.AdView android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="XXXXXXXXXXXXXXXXXXXXXX"/>
</LinearLayout>
Logcat错误:
10-14 19:17:56.787: E/SMD(253): DCD ON
10-14 19:17:59.027: E/memtrack(12061): Couldn't load memtrack module (No such file or directory)
10-14 19:17:59.027: E/android.os.Debug(12061): failed to load memtrack module: -2
10-14 19:17:59.177: E/dalvikvm(12072): >>>>> Normal User
10-14 19:17:59.177: E/dalvikvm(12072): >>>>> com.android.defcontainer [ userId:0 | appId:10006 ]
10-14 19:17:59.787: E/SMD(253): DCD ON
10-14 19:18:02.497: E/PersonaManagerService(732): Unable to read user list
10-14 19:18:02.627: E/LocSvc_flp(732): I/===> int flp_inject_location(FlpLocation*) line 194
10-14 19:18:02.627: E/LocSvc_utils_q(732): D/msg_q_snd: Sending message with handle = 0x7AB2E598
10-14 19:18:02.627: E/LocSvc_utils_ll(732): D/linked_list_add: Adding to list data_obj =
0x7AB2E598
10-14 19:18:02.627: E/LocSvc_utils_q(732): D/msg_q_rcv: Received message 0x7AB2E598 rv = 0
10-14 19:18:02.627: E/LocSvc_api_v02(732): I/---> locClientSendReq line 2332
QMI_LOC_INJECT_POSITION_REQ_V02
10-14 19:18:02.627: E/LocSvc_utils_q(732): D/msg_q_snd: Finished Sending message with handle =
0x7AB2E598
10-14 19:18:02.637: E/LocSvc_ApiV02(732): I/<--- void globalRespCb(locClientHandleType,
uint32_t, locClientRespIndUnionType, void*) line 113 QMI_LOC_INJECT_POSITION_REQ_V02
10-14 19:18:02.637: E/LocSvc_api_v02(732): D/loc_free_slot:299]: freeing slot 0
10-14 19:18:06.097: E/memtrack(12130): Couldn't load memtrack module (No such file or directory)
10-14 19:18:06.097: E/android.os.Debug(12130): failed to load memtrack module: -2
10-14 19:18:06.097: I/CrashAnrDetector(732): onPackageUpdateFinished :
com.XXXXXX.XXXXXX
10-14 19:18:06.137: I/ActivityManager(732): Killing
11524:com.samsung.android.app.gestureservice/1000 (adj 9): empty #26
谢谢你的时间!
答案 0 :(得分:0)
您发布的代码中没有任何内容可用。
虽然您发布的日志中存在大量错误,但这些错误都与Admob无关。
但是在创建Activity时,似乎有些东西会占用UI线程。添加一些日志,找出它的位置和内容。