Advertisement
Guest User

Untitled

a guest
Feb 27th, 2014
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.51 KB | None | 0 0
  1. Logcat error:
  2.  
  3.  
  4.  
  5. 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
  6. 02-27 18:37:14.294: E/AndroidRuntime(31752): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
  7. 02-27 18:37:14.294: E/AndroidRuntime(31752): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2122)
  8. 02-27 18:37:14.294: E/AndroidRuntime(31752): at android.app.ActivityThread.access$600(ActivityThread.java:140)
  9. 02-27 18:37:14.294: E/AndroidRuntime(31752): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1228)
  10. 02-27 18:37:14.294: E/AndroidRuntime(31752): at android.os.Handler.dispatchMessage(Handler.java:99)
  11. 02-27 18:37:14.294: E/AndroidRuntime(31752): at android.os.Looper.loop(Looper.java:137)
  12. 02-27 18:37:14.294: E/AndroidRuntime(31752): at android.app.ActivityThread.main(ActivityThread.java:4895)
  13. 02-27 18:37:14.294: E/AndroidRuntime(31752): at java.lang.reflect.Method.invokeNative(Native Method)
  14. 02-27 18:37:14.294: E/AndroidRuntime(31752): at java.lang.reflect.Method.invoke(Method.java:511)
  15. 02-27 18:37:14.294: E/AndroidRuntime(31752): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23. package com.rkt.ads;
  24.  
  25. import com.google.android.gms.ads.AdRequest;
  26. import com.google.android.gms.ads.AdSize;
  27. import com.google.android.gms.ads.AdView;
  28.  
  29. import android.app.Activity;
  30. import android.os.Bundle;
  31. import android.widget.LinearLayout;
  32.  
  33. public class BannerExample extends Activity {
  34.  
  35. private AdView adView;
  36.  
  37. private static final String AD_UNIT_ID = "/6253334/dfp_example_ad/interstitial";
  38.  
  39. @Override
  40. public void onCreate(Bundle savedInstanceState) {
  41. super.onCreate(savedInstanceState);
  42. setContentView(R.layout.activity_main);
  43.  
  44. adView = new AdView(this);
  45. adView.setAdSize(AdSize.BANNER);
  46. adView.setAdUnitId(AD_UNIT_ID);
  47.  
  48. LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout);
  49. layout.addView(adView);
  50.  
  51. AdRequest adRequest = new AdRequest.Builder()
  52. .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
  53. .addTestDevice("INSERT_YOUR_HASHED_DEVICE_ID_HERE").build();
  54.  
  55. adView.loadAd(adRequest);
  56. }
  57.  
  58. @Override
  59. public void onResume() {
  60. super.onResume();
  61. if (adView != null) {
  62. adView.resume();
  63. }
  64. }
  65.  
  66. @Override
  67. public void onPause() {
  68. if (adView != null) {
  69. adView.pause();
  70. }
  71. super.onPause();
  72. }
  73.  
  74. /** Called before the activity is destroyed. */
  75. @Override
  76. public void onDestroy() {
  77.  
  78. if (adView != null) {
  79. adView.destroy();
  80. }
  81. super.onDestroy();
  82. }
  83. }
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91. <?xml version="1.0" encoding="utf-8"?>
  92. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  93. xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
  94. android:id="@+id/linearLayout"
  95. android:layout_width="fill_parent"
  96. android:layout_height="fill_parent"
  97. android:orientation="vertical" >
  98.  
  99. <com.google.ads.AdView
  100. android:id="@+id/adView"
  101. android:layout_width="300dp"
  102. android:layout_height="300dp"
  103. ads:adSize="BANNER"
  104. ads:loadAdOnCreate="true" >
  105. </com.google.ads.AdView>
  106.  
  107. </LinearLayout>
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118. <?xml version="1.0" encoding="utf-8"?>
  119. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  120. package="com.rkt.ads"
  121. android:versionCode="1"
  122. android:versionName="1.0" >
  123.  
  124. <uses-sdk
  125. android:minSdkVersion="15"
  126. android:targetSdkVersion="18" />
  127.  
  128. <uses-permission android:name="android.permission.INTERNET" />
  129. <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  130.  
  131. <application
  132. android:allowBackup="true"
  133. android:icon="@drawable/ic_launcher"
  134. android:label="@string/app_name"
  135. android:theme="@style/AppTheme" >
  136. <activity
  137. android:name="com.rkt.ads.BannerExample"
  138. android:label="@string/app_name" >
  139. <intent-filter>
  140. <action android:name="android.intent.action.MAIN" />
  141.  
  142. <category android:name="android.intent.category.LAUNCHER" />
  143. </intent-filter>
  144. </activity>
  145. <activity
  146. android:name="com.google.ads.AdActivity"
  147. android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
  148. </application>
  149.  
  150. </manifest>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement