Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Logcat error:
- 02-27 18:37:14.294: E/AndroidRuntime(31752): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.rkt.ads/com.rkt.ads.BannerExample}: android.view.InflateException: Binary XML file line #9: Error inflating class com.google.ads.AdView
- 02-27 18:37:14.294: E/AndroidRuntime(31752): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
- 02-27 18:37:14.294: E/AndroidRuntime(31752): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2122)
- 02-27 18:37:14.294: E/AndroidRuntime(31752): at android.app.ActivityThread.access$600(ActivityThread.java:140)
- 02-27 18:37:14.294: E/AndroidRuntime(31752): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1228)
- 02-27 18:37:14.294: E/AndroidRuntime(31752): at android.os.Handler.dispatchMessage(Handler.java:99)
- 02-27 18:37:14.294: E/AndroidRuntime(31752): at android.os.Looper.loop(Looper.java:137)
- 02-27 18:37:14.294: E/AndroidRuntime(31752): at android.app.ActivityThread.main(ActivityThread.java:4895)
- 02-27 18:37:14.294: E/AndroidRuntime(31752): at java.lang.reflect.Method.invokeNative(Native Method)
- 02-27 18:37:14.294: E/AndroidRuntime(31752): at java.lang.reflect.Method.invoke(Method.java:511)
- 02-27 18:37:14.294: E/AndroidRuntime(31752): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
- package com.rkt.ads;
- import com.google.android.gms.ads.AdRequest;
- import com.google.android.gms.ads.AdSize;
- import com.google.android.gms.ads.AdView;
- import android.app.Activity;
- import android.os.Bundle;
- import android.widget.LinearLayout;
- public class BannerExample extends Activity {
- private AdView adView;
- private static final String AD_UNIT_ID = "/6253334/dfp_example_ad/interstitial";
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- adView = new AdView(this);
- adView.setAdSize(AdSize.BANNER);
- adView.setAdUnitId(AD_UNIT_ID);
- LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout);
- layout.addView(adView);
- AdRequest adRequest = new AdRequest.Builder()
- .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
- .addTestDevice("INSERT_YOUR_HASHED_DEVICE_ID_HERE").build();
- adView.loadAd(adRequest);
- }
- @Override
- public void onResume() {
- super.onResume();
- if (adView != null) {
- adView.resume();
- }
- }
- @Override
- public void onPause() {
- if (adView != null) {
- adView.pause();
- }
- super.onPause();
- }
- /** Called before the activity is destroyed. */
- @Override
- public void onDestroy() {
- if (adView != null) {
- adView.destroy();
- }
- super.onDestroy();
- }
- }
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
- android:id="@+id/linearLayout"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:orientation="vertical" >
- <com.google.ads.AdView
- android:id="@+id/adView"
- android:layout_width="300dp"
- android:layout_height="300dp"
- ads:adSize="BANNER"
- ads:loadAdOnCreate="true" >
- </com.google.ads.AdView>
- </LinearLayout>
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.rkt.ads"
- android:versionCode="1"
- android:versionName="1.0" >
- <uses-sdk
- android:minSdkVersion="15"
- android:targetSdkVersion="18" />
- <uses-permission android:name="android.permission.INTERNET" />
- <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
- <application
- android:allowBackup="true"
- android:icon="@drawable/ic_launcher"
- android:label="@string/app_name"
- android:theme="@style/AppTheme" >
- <activity
- android:name="com.rkt.ads.BannerExample"
- 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.ads.AdActivity"
- android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
- </application>
- </manifest>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement