Admob崩溃应用程序

时间:2014-09-15 06:13:50

标签: java android xml google-play admob

我尝试先运行我的代码而不使用admob。它工作正常。然后我尝试使用admob运行我的代码应用程序只是在启动时崩溃并不显示消息只是崩溃。 我已经为activity main和layout.xml以及manifest提供了代码。如果您需要查看imageAdapter和GalleryFlow,我也会发布。 这是我的代码:

   public class ActivityMain extends Activity {
   private GalleryFlow mGalleryFlow;
   private AdView adView;
   private InterstitialAd interstitial;

      private int[] imageIds = new int[] { R.drawable.gal1, R.drawable.gal2,
            R.drawable.gal3, R.drawable.gal4, R.drawable.gal5,
            R.drawable.gal6, R.drawable.gal7, R.drawable.gal8,
            R.drawable.gal9, R.drawable.gal10, R.drawable.gal11,
            R.drawable.gal12, R.drawable.gal13, R.drawable.gal14,
            R.drawable.gal15, R.drawable.gal16, R.drawable.gal17,};
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout_gallery);

    findViews();
     initViews();
    adView = new AdView(this);
    adView.setAdSize(AdSize.SMART_BANNER);
    adView.setAdUnitId("MY ID HERE");


     RelativeLayout layout = (RelativeLayout) findViewById(R.id.layoutAdView);
     layout.addView(adView);


     AdRequest adRequest = new AdRequest.Builder()
        .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
        .addTestDevice("INSERT_YOUR_HASHED_DEVICE_ID_HERE")
        .build();


    adView.loadAd(adRequest);

    interstitial = new InterstitialAd(this);
    interstitial.setAdUnitId("MY ID HERE");

      AdRequest adRequest1 = new AdRequest.Builder().build();
    interstitial.loadAd(adRequest);
    interstitial.setAdListener(new AdListener() {
        public void onAdLoaded() {
            displayInterstitial();
        }
    });
    }

    public void displayInterstitial() {
    if (interstitial.isLoaded()) {
        interstitial.show();
    }
    }






    private void findViews() {
        mGalleryFlow = (GalleryFlow) findViewById(R.id.Gallery01);
    }

    private void initViews() {
        ImageAdapter adapter = new ImageAdapter(this, imageIds);

        adapter.createReflectedImages();
        mGalleryFlow.setAdapter(adapter);
    }


}    

布局xml

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  xmlns:ads="http://schemas.android.com/apk/res-auto" 
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context=".Runhere"
  android:background="#FFA500" >


 <com.norka.gallery.GalleryFlow 
 android:id="@+id/Gallery01" 
 android:layout_width="match_parent" 
 android:layout_height="match_parent"/>

  <RelativeLayout 
android:id="@+id/layoutAdView"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="50dp" 
android:layout_alignParentBottom="true"
android:gravity="center_horizontal" />

</RelativeLayout>

我的manifest.xml

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.norka.gallery"
    android:versionCode="1"
    android:versionName="1.0">

      <uses-permission android:name="android.permission.INTERNET"/>
      <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
     <uses-sdk
    android:minSdkVersion="10"
    android:targetSdkVersion="10" />



     <application android:icon="@drawable/icon" android:label="@string/app_name">

     <activity android:name="com.google.android.gms.ads.AdActivity"
          android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
      <activity android:name="com.norka.gallery.ActivityMain"
              android:label="@string/app_name">


        <meta-data android:name="com.google.android.gms.version"
       android:value="@integer/google_play_services_version"/>


        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
          </intent-filter>
       </activity>

   </application>


</manifest> 

logcat的

09-15 07:32:38.798: I/MultiDex(30217): install
09-15 07:32:38.798: I/MultiDex(30217): MultiDexExtractor.load(/data/downloads/PrebuiltGmsCore.apk, false)
09-15 07:32:38.808: I/MultiDex(30217): loading existing secondary dex files
09-15 07:32:38.808: I/MultiDex(30217): load found 1 secondary dex files
09-15 07:32:38.808: I/MultiDex(30217): install done
09-15 07:32:38.808: I/ProviderInstaller(30217): Insert disabled by gate 'gms:security:enable_conscrypt_in_gms_application'
09-15 07:32:38.828: I/MultiDex(30234): install
09-15 07:32:38.828: I/MultiDex(30234): MultiDexExtractor.load(/data/downloads/PrebuiltGmsCore.apk, false)
09-15 07:32:38.838: D/PackageBroadcastService(30217): Received broadcast action=android.intent.action.PACKAGE_REMOVED and uri=com.norka.gallery
09-15 07:32:38.838: D/dalvikvm(30217): Trying to load lib /data/downloads/libAppDataSearch.so 0x95fb0a40
09-15 07:32:38.838: E/dalvikvm(30217): dlopen("/data/downloads/libAppDataSearch.so") failed: dlopen failed: "/data/downloads/libAppDataSearch.so" has unexpected e_machine: 40
09-15 07:32:38.838: E/Icing(30217): Native load error: dlopen failed: "/data/downloads/libAppDataSearch.so" has unexpected e_machine: 40
09-15 07:32:38.838: I/MultiDex(30234): loading existing secondary dex files
09-15 07:32:38.838: I/MultiDex(30234): load found 1 secondary dex files
09-15 07:32:38.838: I/MultiDex(30234): install done
09-15 07:32:38.848: I/Icing(30217): Storage manager: low false usage 9.34KB avail 6.17GB capacity 6.59GB
09-15 07:32:38.858: I/ProviderInstaller(30234): Insert disabled by gate 'gms:security:enable_conscrypt_in_gms_application'
09-15 07:32:38.868: D/dalvikvm(30217): GC_FOR_ALLOC freed 430K, 21% free 2955K/3728K, paused 0ms, total 0ms
09-15 07:32:38.938: E/Icing(30217): Error initializing, resetting corpora: Could not create native index
09-15 07:32:38.938: E/Icing(30217): Internal init failed
09-15 07:32:38.938: E/Icing(30217): Couldn't handle android.intent.action.PACKAGE_REMOVED intent due to initialization failure.
09-15 07:32:39.108: D/PackageBroadcastService(30217): Received broadcast action=android.intent.action.PACKAGE_ADDED and uri=com.norka.gallery
09-15 07:32:39.178: E/Icing(30217): Couldn't handle android.intent.action.PACKAGE_ADDED intent due to initialization failure.
09-15 07:32:39.218: I/PeopleContactsSync(30217): CP2 sync disabled
09-15 07:32:39.318: D/dalvikvm(30217): GC_FOR_ALLOC freed 590K, 17% free 3189K/3812K, paused 0ms, total 0ms
09-15 07:32:39.758: D/PackageBroadcastService(30217): Received broadcast action=android.intent.action.PACKAGE_REPLACED and uri=com.norka.gallery
09-15 07:32:39.758: E/Icing(30217): Couldn't handle android.intent.action.PACKAGE_REPLACED intent due to initialization failure.

09-15 07:32:39.758:I / PeopleContactsSync(30217):禁用CP2同步

1 个答案:

答案 0 :(得分:-1)

在XML代码中声明adView会更好。它可以防止你看到的奇怪东西发生。这是一个如何用XML声明它的例子。

<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" style="@style/background">

  <com.google.ads.AdView android:id="@+id/adView"
     ads:loadAdOnCreate="true" 
     ads:adSize="BANNER" 
     ads:adUnitId="@string/admob_unit_id"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content" >
   </com.google.ads.AdView>
 </RelativeLayout>