Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/221.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
显示admob横幅时出现android异常_Android - Fatal编程技术网

显示admob横幅时出现android异常

显示admob横幅时出现android异常,android,Android,在通过xml文件添加google广告后,我的应用程序抛出了一个异常 <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" android:id="@+id/drawer_layout" android:layout_width

在通过xml文件添加google广告后,我的应用程序抛出了一个异常

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">


<RelativeLayout 
    android:id="@+id/container"
    android:layout_width="match_parent"
android:layout_height="match_parent">

<com.google.ads.AdView
android:id="@+id/adview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
ads:adUnitId="ca-app-pub-9712480410915966/3388723331"
ads:adSize="BANNER"
ads:testDevices="TEST_EMULATOR"
ads:loadAdOnCreate="true"
/>

<ImageView 

android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/homepage"
android:scaleType="fitXY"
/>
<ImageView 
android:id="@+id/imageView2"
android:layout_width="match_parent"
android:visibility="visible"
android:layout_height="match_parent"
android:src="@drawable/sub1"   
/>
</RelativeLayout>
<ListView 
    android:id="@+id/drawerlist"
    android:background="#0099CC"
    android:cacheColorHint="#00000000" 

    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="left" ></ListView>


</android.support.v4.widget.DrawerLayout>

你需要把这个放在你的课堂上:

AdView adView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().addTestDevice(
                AdRequest.DEVICE_ID_EMULATOR).build();
adView.loadAd(adRequest);
在这里,您可以学习完整的教程:


您的类的代码在哪里?在代码中,我无法为adsI添加任何内容。我已经添加了一个关于您必须在classIn代码中添加的代码的注释。如果我添加这些行,我会得到一个错误,即“为AdView创建类”,它不能告诉我导入AdViewI建议你按照我发布的完整教程一步一步来修复你的错误。
    07-10 17:07:17.627: D/AndroidRuntime(1244): Shutting down VM
07-10 17:07:17.627: W/dalvikvm(1244): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
07-10 17:07:17.671: E/AndroidRuntime(1244): FATAL EXCEPTION: main
07-10 17:07:17.671: E/AndroidRuntime(1244): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.diveintojava1/com.example.diveintojava1.MainActivity}: android.view.InflateException: Binary XML file line #13: Error inflating class com.google.ads.AdView
07-10 17:07:17.671: E/AndroidRuntime(1244):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
07-10 17:07:17.671: E/AndroidRuntime(1244):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
07-10 17:07:17.671: E/AndroidRuntime(1244):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
07-10 17:07:17.671: E/AndroidRuntime(1244):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
07-10 17:07:17.671: E/AndroidRuntime(1244):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-10 17:07:17.671: E/AndroidRuntime(1244):     at android.os.Looper.loop(Looper.java:137)
07-10 17:07:17.671: E/AndroidRuntime(1244):     at android.app.ActivityThread.main(ActivityThread.java:5041)
07-10 17:07:17.671: E/AndroidRuntime(1244):     at java.lang.reflect.Method.invokeNative(Native Method)
07-10 17:07:17.671: E/AndroidRuntime(1244):     at java.lang.reflect.Method.invoke(Method.java:511)
07-10 17:07:17.671: E/AndroidRuntime(1244):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-10 17:07:17.671: E/AndroidRuntime(1244):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-10 17:07:17.671: E/AndroidRuntime(1244):     at dalvik.system.NativeStart.main(Native Method)
07-10 17:07:17.671: E/AndroidRuntime(1244): Caused by: android.view.InflateException: Binary XML file line #13: Error inflating class com.google.ads.AdView
07-10 17:07:17.671: E/AndroidRuntime(1244):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:698)
07-10 17:07:17.671: E/AndroidRuntime(1244):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
07-10 17:07:17.671: E/AndroidRuntime(1244):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
07-10 17:07:17.671: E/AndroidRuntime(1244):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
AdView adView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().addTestDevice(
                AdRequest.DEVICE_ID_EMULATOR).build();
adView.loadAd(adRequest);